I am trying to send email in my play! framework 1.2.5
app with Amazon SES
. As I search, I can not define configuration of amazon SES mail in application.conf. And I created a job which set configuration in java. However I am getting the following exception. For whole day, I am trying to make my app send email. But any try failed. I thought you may help me.
I appreciate.
@OnApplicationStart
public class Bootstrap extends Job{
@Override
public void doJob() throws Exception {
Properties props = play.libs.Mail.getSession().getProperties();
props.setProperty("mail.transport.protocol","aws");
props.setProperty("mail.smtp.host","email-smtp.eu-west-1.amazonaws.com");
props.setProperty("mail.smtp.port","25");
props.setProperty("mail.aws.user", "...");
props.setProperty("mail.aws.password", "...");
System.out.println("AMAZON SES-MAIL PROPERTIES SET SUCCESSFULY");
}
}
Error
play.exceptions.MailException: Error while sending email
at play.libs.Mail$2.call(Mail.java:186)
at play.libs.Mail$2.call(Mail.java:178)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : email-smtp.eu-west-1.amazonaws.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at play.libs.Mail$2.call(Mail.java:183)
... 6 more
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 Authentication required
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at javax.mail.Transport.send0(Transport.java:191)
at javax.mail.Transport.send(Transport.java:120)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 8 more
That my question is not answered. And I found out what my problem was. I explain it so that some others having such problem can benefit from. Since the begining, I think my problem was not to define specific ports for outgoing SMTP calls in security-group. This is a good article you can read. Furthermore no need to configure AWS SES in any bootstrap class. I have just defined it in application.conf as I showed below.
mail.transport.protocol=aws
mail.smtp.host=<your aws smpt server name>
mail.smtp.port=587
mail.smtp.user=<your username>
mail.smtp.pass=<your password>
mail.smtp.channel=ssl
However mails goes to spam folder and I could not find why it is happing like that. If anbody having any idea about that write a comment here I would appreciate :)