Apache Email API : Getting an Exception - Invalid 'To' address
I am using the Apache commons mail API to send an email through a Java program.
Following is the java code.
public static void sendSimpleMail() throws Exception {
Email email = new SimpleEmail();
email.setSmtpPort(25);
email.setDebug(false);
email.setHostName("localhost");
email.setFrom("user1@test.com"); // Is this correct ?Do we need this?
email.setSubject("Hi");
email.setMsg("This is a test mail ... :-)");
email.addTo("myname@mycompany.com");
email.setTLS(true);
email.send();
System.out.println("Mail sent!");
}
I have the Free SMTP server running on port 25 using a valid DNS server.
Now , when i run the program, I get the following exception.
Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : localhost:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at TestMail.sendSimpleMail(TestMail.java:26)
at TestMail.main(TestMail.java:13)
Caused by: com.sun.mail.smtp.SMTPSendFailedException:
550 Invalid recipient: myname@mycompany.com
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(S开发者_开发百科MTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1215)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:586)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 3 more
Now, my email id is a very valid email id. Why is the program giving such an error?
550 is a standard SMTP error code, so the problem seems to be lying somewhere within the SMTP server configuration. Verify that you can send an email by hand to the given email address (telnet localhost 25), if you can't then it has nothing to do with Apache.
精彩评论