Sending email from Scala / Play Framework version 2.3.6

I have just successfully sent an email from Play / Scala.  This is what I did:

1.  Add ”” %% “play-plugins-mailer” % “2.3.1” to libraryDependencies (build.sbt)

2.  Add the following to application.conf:

Email config smtp.port=465 smtp.ssl=yes smtp.tls=yes smtp.user=”” smtp.password=my_password

I_f you use a ! in your smtp.password, put a “” round “!” (as ! is a reserved character).  Change your smtp.user (to your own email address)._

3. Create a new file conf/play.plugins:


 4. Add the following to routes:

GET /email controllers.Application.sendEmail

 5. Completely replace controllers/Application.scala (change the Recipient and From email addresses):

package controllers

import play.api.mvc._
import com.typesafe.plugin._
import play.api.Play.current

object Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))

  def sendEmail() = Action {
    val mail = use[MailerPlugin].email
    mail.setRecipient("Miles Davenport <>","")
    //or use a list
    //mail.setBcc(List("Dummy <>", "Dummy2 <>"):_*)
    mail.setFrom("Miles Davenport <>")
    //adds attachment
    //mail.addAttachment("attachment.pdf", new File("/some/path/attachment.pdf"))
    //adds inline attachment from byte array
    //val data: Array[Byte] = "data".getBytes
    //mail.addAttachment("data.txt", data, "text/plain", "A simple file", EmailAttachment.INLINE)
    //sends html
    //mail.sendHtml("<html>html</html>" )
    //sends text/text
    mail.send( "text" )
    //sends both text and html
    //mail.send( "text", "<html>html</html>")

6. Start Play. Point your favourite web browser at http://localhost:9000/email

Your browser should say Hello. Check your email. You should have a new email, with a subject of “mailer” :O)

More information is available from

Author | Miles Davenport

Career programmer, who designs, assembles, fixes, and supports customers, software and systems.