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 <
[email protected]> 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