Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sending Email with JSP (unable to send to certain email addresses e.g. hotmail.com, rocketmail.com etc)

Posted on 2004-10-03
8
Medium Priority
?
362 Views
Last Modified: 2010-08-05
Hi,

I found a JSP coding by kheefatt to send email with JSP in this forum.

The coding is as below:

send_mail.jsp
----------------

<%@ page language="java" import="java.sql.*, java.util.ArrayList" %>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<html>
<head>
</head>
<body>
<table width="50%" border="0" >
<tr>
<td>
<%
     String emailAdd = request.getParameter("receiver");
     String mailBody = request.getParameter("mailtext");
     boolean mail_error = false;
     String errMsg = "";

     try
     {
          Properties props = new Properties();
          props.put("mail.smtp.host", "127.0.0.1");  //replace 127.0.0.1 with the name u specify in your mail server
          Session s = Session.getInstance(props,null);
          MimeMessage message = new MimeMessage(s);
          InternetAddress from = new InternetAddress(emailAdd);
          message.setFrom(from);
          InternetAddress to = new InternetAddress("kheefatt@yahoo.com"); //your email address
          message.addRecipient(Message.RecipientType.TO, to);
          message.setSubject("Mail Test!");
          message.setText(mailBody);
          Transport.send(message);
     }
     catch (Exception ex)
     {
          String titleMsg = "Error Exception";
          errMsg = ex.getMessage();
          mail_error = true;
     }    
     if (mail_error==false)
          out.write("Thank you for subscribing to our newsletter.<BR>");
     else if (mail_error==true)
     {
          out.write("There's an error in the mail server. Please try again later!<BR>\n");
     }
%>
</td>
</tr>
</table>
</body>
</html>


I replace the 127.0.0.1 in props.put("mail.smtp.host", "127.0.0.1") with the address I usually put in the SMTP serve section of my Outlook Express (mail.mycompany.com). I was able to sent to all mycompany.com accounts (i.e xxx@mycompany.com) but was unable to send other account such as xxx@hotmail. What did I do wrong?
FYI, the mail server is provided by the hosting company. We rented a webspace with a hosting company, and the package include email accounts.
0
Comment
Question by:minevra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:raj3060
ID: 12212685
you probably need to putr the IP address with the port
i.e.
props.put("mail.smtp.host", "127.0.0.1:8080")
0
 

Expert Comment

by:kheefatt
ID: 12214825
I think it is sent to the junk mail folder. Check your junk mail folder and see.

It is impossible it works on all your mycompany.com accounts but not to hotmail. Try to disable your junk mail filter and try again. Good luck!
0
 
LVL 1

Author Comment

by:minevra
ID: 12215108
There is nothing wrong with hotmail. There is actualy error in the program when I try to sent to hotmail.

Here is the error message:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Sending failed;
  nested exception is:
      class javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
      class javax.mail.SendFailedException: 550 not local host roketmail.com, not a gateway

      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:682)
      org.apache.jsp.testmail_jsp._jspService(testmail_jsp.java:74)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

javax.mail.SendFailedException: Sending failed;
  nested exception is:
      class javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
      class javax.mail.SendFailedException: 550 not local host roketmail.com, not a gateway

      javax.mail.Transport.send0(Transport.java:218)
      javax.mail.Transport.send(Transport.java:80)
      org.apache.jsp.testmail_jsp._jspService(testmail_jsp.java:64)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:kheefatt
ID: 12215119
contact your hosting company and asked them bout the specified ip and port
0
 
LVL 1

Author Comment

by:minevra
ID: 12215216
hi kheefatt,

I found out that I have to put in my username and password in order to send outside our own company account. How can I do that?

Can u show me the code?

thanks
0
 

Expert Comment

by:kheefatt
ID: 12215234
I think u haf the application did wrongly. U dont need to put in any username and password in order to send a mail through a mail server. U download a free smtp mail server and try it out on yur local pc first.
props.put("mail.smtp.host", "127.0.0.1") <-- u put in the IP or the name of the mail server, not your email account.
0
 
LVL 1

Author Comment

by:minevra
ID: 12215250
This is what my colleague told me. She did a similar program before and she also face the same problem until still put in username and password (I can't use her codes because it's very different from mine). My hosting company purposely set their servers to require authentication to sent mail. This is to prevent spamming.
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 500 total points
ID: 12215820
in JavaMail API you can set username and password for SMTP authentication.
Check following code http://www.javacommerce.com/articles/SendMailUsingAuthentication.java
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
As much as Microsoft wants to kill off PST file support, just as they tried to do with public folders, there are still times when it is useful or downright necessary to export Exchange mailboxes to PST files. Thankfully, it is still possible to e…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question