1
votes

I'm trying to send a simple test email through SendGrid from my Java Play 2.10 application. I'm using the play-plugins-mailer to send the email and have a free (heroku) SendGrid account. This is everything I've done so far for:

  • Added the play-plugins-mailer dependency to my Build.scala
  • Added the CommonsMailerPlugin to my play.plugins file
  • Added the following code in my controller to send an email:

    MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
    mail.setSubject("test subject");
    mail.addRecipient("[email protected]");
    mail.addFrom("[email protected]");
    mail.send("some text");
    
  • Added the following in my application.conf:

    smtp.host="smtp.sendgrid.net"
    smtp.user="[my-sendgrid-user]"
    smtp.pass="[my-sendgrid-pass]"
    smtp.port="587"
    smtp.channel=plain
    

I'm pretty sure the Mailer is working fine, it just seems to be a SendGrid configuration issue. When this code gets executed I get this error:

[RuntimeException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.sendgrid.net:587]

I've tried running this on my local machine as well as on heroku where I've added the SendGrid plugin to my app.

3

3 Answers

1
votes

Have you had a look at this thread? Send mail in Heroku using SendGrid

Also, you might what to try the Typesafe mail plug as described in this tutorial:

http://blog.flurdy.com/2012/05/send-email-via-sendgrid-on-heroku-using.html

1
votes

I think you can use the Java API given here at official SendGrid-java Jithub project.

Official Send-Grid Java API

0
votes