GeeCON Prague 2014*
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
Author

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.io.*;
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("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(sessionDebug);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
msg.setText(messageText);
Transport.send(msg);
}
catch (MessagingException mex){
mex.printStackTrace();
}
}
}
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 thunder5.cwihosting.com [64.49.223.20] is not permitted
550-to relay through thunder5.cwihosting.com.
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 <ddalton@noln.com> prohibited by administrator
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at mailServ.sendEmail(mailServ.java:42)
at newUserSignUp.doPost(newUserSignUp.java:90)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:83)
at com.caucho.server.http.Invocation.service(Invocation.java:325)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:333)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:266)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
any & all help would be truely appreciated!! Thanks Much
Jayanthimeena
Greenhorn

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
Greenhorn

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

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 );
try
{
message.saveChanges();
tr.sendMessage( message, message.getAllRecipients() );
}
finally
{
tr.close();
}
For me it's working so I hope it will help you.

Bye ThE_GuEsT
be nice... I like the terms of this site
alzamabar
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


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaMail Exception.......HELP!!