javaemailsimple-java-mail

How to send mail using Simple Java Mail framework?


I use Simple Java Mail framework for sending mail. I read documentation there - simplejavamail.org.

My code:

Email email = new Email();
email.setFromAddress("SomeOne1", "someone1@aol.com");
email.setSubject("Newsletter");
email.addRecipient("SomeOne2", "someone2@aol.com", Message.RecipientType.TO);
email.setText("Some text");
email.setTextHTML("there my html");

new Mailer("smtp.aol.com", 587, "testjavasimplemail@gmail.com", "hunter2", TransportStrategy.SMTP_TLS).sendMail(email);

But now I have error:

июн 25, 2015 6:30:47 PM org.codemonkey.simplejavamail.Mailer sendMail
SEVERE: null
javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:319)
    at javax.mail.Service.connect(Service.java:169)
    at javax.mail.Service.connect(Service.java:118)
    at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:242)
    at pkg.Main.main(Main.java:39)

Exception in thread "main" org.codemonkey.simplejavamail.MailException: Generic error: null
    at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:250)
    at pkg.Main.main(Main.java:39)
Caused by: javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:319)
    at javax.mail.Service.connect(Service.java:169)
    at javax.mail.Service.connect(Service.java:118)
    at org.codemonkey.simplejavamail.Mailer.sendMail(Mailer.java:242)
    ... 1 more

What's wrong?


Solution

  • You're using the wrong SMTP server. You need the GMail one.

    "smtp.aol.com" -> "smtp.gmail.com"