Alexiuscrow
Alexiuscrow

Reputation: 785

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", "[email protected]");
email.setSubject("Newsletter");
email.addRecipient("SomeOne2", "[email protected]", Message.RecipientType.TO);
email.setText("Some text");
email.setTextHTML("there my html");

new Mailer("smtp.aol.com", 587, "[email protected]", "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?

Upvotes: 0

Views: 3863

Answers (2)

noelm
noelm

Reputation: 1302

You are using an gmail account to connect to an aol smtp server !

Try with the good parameters ...

Upvotes: 0

artbristol
artbristol

Reputation: 32397

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

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

Upvotes: 1

Related Questions