title: Play Mailer plugin with Play 2.5
body: <p>I am struggling with play mailer plugin. I found many references to configure play-mailer plugin to send email using gmail, but none worked.</p>
  
  <p>Here are the details -</p>
  
  <ol>
  <li>Play 2.5 </li>
  <li>Scala 2.11</li>
  <li>mailer plugin - <code>"com.typesafe.play" %% "play-mailer" % "5.0.0"</code></li>
  </ol>
  
  <p>And here is my code:</p>
  
  <h3>application.conf:</h3>
  
  <pre><code>play.mailer {
      host="smtp.gmail.com"
      port=587
      ssl=no
      tls=yes
      user="pariXXXXXX@gmail.com"
      password="XXXXXX"
      debug=no
      timeout=60
      connectiontimeout=60
      mock=false
  }
  </code></pre>
  
  <h3>Controller:</h3>
  
  <pre><code>class HomeController @Inject() (
      val messagesApi: MessagesApi,
      val mailer:MailerClient)
  extends Controller with I18nSupport {
      def index = Action {
          val bodyHtml = Some(views.html.mails.welcome("Pari").toString)
          val email = Email(subject = "subject", from = "pari.XXXXX@gmail.com", to = List("pari.XXXXX@gmail.com"), bodyHtml = bodyHtml, bodyText = Some("Hello"), replyTo = None)
          mailer.send(email)
          Ok("Did you receive my email?")
      }
  }
  </code></pre>
  
  <h3>Error:</h3>
  
  <pre><code>Execution exception[[EmailException: Sending the email to the following server failed : smtp.gmail.com:587]]
      at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
      at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
      at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
      at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
      at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
      at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
      at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
      at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
      at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
      at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
  Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
      at org.apache.commons.mail.Email.send(Email.java:1448)
      at play.api.libs.mailer.SMTPMailer$$anon$2.send(MailerPlugin.scala:100)
      at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:130)
      at play.api.libs.mailer.SMTPMailer.send(MailerPlugin.scala:110)
      at play.api.libs.mailer.SMTPDynamicMailer.send(MailerPlugin.scala:117)
      at controllers.HomeController$$anonfun$index$1.apply(HomeController.scala:82)
      at controllers.HomeController$$anonfun$index$1.apply(HomeController.scala:79)
      at play.api.mvc.ActionBuilder$$anonfun$apply$14.apply(Action.scala:403)
      at play.api.mvc.ActionBuilder$$anonfun$apply$14.apply(Action.scala:403)
  Caused by: javax.mail.MessagingException: Exception reading response
      at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2202)
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1939)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
      at javax.mail.Service.connect(Service.java:317)
      at javax.mail.Service.connect(Service.java:176)
      at javax.mail.Service.connect(Service.java:125)
      at javax.mail.Transport.send0(Transport.java:194)
      at javax.mail.Transport.send(Transport.java:124)
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
      at org.apache.commons.mail.Email.send(Email.java:1448)
  Caused by: java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
      at java.net.SocketInputStream.read(SocketInputStream.java:170)
      at java.net.SocketInputStream.read(SocketInputStream.java:141)
      at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
      at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
      at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2182)
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1939)
  </code></pre>
  
  <p>Any thoughts?</p>
  
  <p>P.S. I have enabled less secure access for gmail account as well.</p>