File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes JavaMail Exception.......HELP!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JavaMail Exception.......HELP!!" Watch "JavaMail Exception.......HELP!!" New topic

JavaMail Exception.......HELP!!

DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Ive written a class to send email from a website Im working on & am beating my head against the desk trying to figure out why i keep getting exceptions from my implementation of JavaMail. I originally tested this using my local machine & local isp which worked fine. I then contacted my sites hosting company about the default email server for my site. They told me it was just my domain name so i changed the smtp host to the domain name. Now I get an exception everytime i try to send email to anyone but the sites email address. I changed the file back to my local isp (still running from site) & it will only send email to my home address....I hope someone has a clue here. My tech support people are slower than death & this needs to be finished asap.
Here is the class for mail sending:
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class mailServ extends HttpServlet{
public void sendEmail (String userName, String passWord, String emailAddy) {
String host = "[myurl]";
String to = emailAddy;
String from = "[my default site email address]";
String subject = "Your Username and Password";
String messageText = "Welcome to Our site! \n\nYour username is: "+userName+" and your password is: "+passWord+" \n \nOnce you have logged into the site you may change your password to something easier to remember by going to the help link located at the top of every page of the site.";

boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSentDate(new java.util.Date());
catch (MessagingException mex){
AND Here's the exception Im getting:
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550-Host [] is not permitted
550-to relay through
550-Perhaps you have not logged into the pop/imap server in the last 30 minutes.
550-You may also have been rejected because your ip address
550-does not have a reverse DNS entry.
550 relaying to <> prohibited by administrator
at javax.mail.Transport.send0(
at javax.mail.Transport.send(
at mailServ.sendEmail(
at newUserSignUp.doPost(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at com.caucho.server.http.Invocation.service(
at com.caucho.server.http.RunnerRequest.handleRequest(
at com.caucho.server.http.RunnerRequest.handleConnection(
any & all help would be truely appreciated!! Thanks Much

Joined: Jul 24, 2001
Posts: 17
I also faced the similar problem,
The smpt server provider has to give rights to user the for a particular port.
Transport transport = session.getTransport("smtp");
transport.connect(smtpserver," ", " ");
If it is provided corectley then all will work fine.
if you need i will give full coding.
to check the particular port is given permission, check sending mail to admin or faq person.
hope this will help u
Rohan Baweja
Ranch Hand

Joined: Aug 19, 2001
Posts: 31
Hi Dalton
I think the problem lies in the code where you have written:
Session session = Session.getDefaultInstance(props, null);
I am not very good with javamail. I think you are passing a null value before getting an instance of the session object.
Correct use is:
Session getDefaultInstance(java.util.Properties props, Authenticator authenticator).
You are not authenticating yourself on the smtp server before getting the session instance. I think you should use a Authenticator object instead of null.
I think it'll help you.
nagendra barla

Joined: Aug 17, 2001
Posts: 4
Set the properties properly.
set correct value for "" .u give u'r internet provider smtp server ip address the above property,then u can send mails to any domain.
benoit not divulgued

Joined: Jan 23, 2004
Posts: 1
Hi DC Dalton,
I had the same problem and so after passing few minutes in the javadoc of JavaMail I'd found this :
Transport tr = agentSession.getTransport( "smtp" );
tr.connect( host, port, username, password );
tr.sendMessage( message, message.getAllRecipients() );
For me it's working so I hope it will help you.

Bye ThE_GuEsT
be nice... I like the terms of this site
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
Hi, ensure that you have setup the following property in the Properties object that you pass into the constructor of the Session object:

prop.put("mail.smtp.auth", "true");


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
I agree. Here's the link:
subject: JavaMail Exception.......HELP!!
It's not a secret anymore!