Adding an “Email sending” functionality in Play using Scala

To provide an “Email Sending ” functionality in your Play App that is being built with Play 2.2.1, follow these steps ( this post summarizes the work done step by step).

1) Add following dependency in build.sbt (or in Build.scala for Play 2.1.x or older versions)

“com.typesafe” %% “play-plugins-mailer” % “2.1-RC2”

2) Add following lines to “conf/application.conf” file
smtp.user="" <-- your email id within double quotes
smtp.password=yourpassword <-- without double qoutes

3) Create a new File in conf folder with name “play.plugins” and add following line into it


4) Delete all the code in “Application.scala” and write following code to it

package controllers

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

object Application extends Controller {

 case class MailData(email: String)

 val mailForm = Form(
   "email" -> email)(MailData.apply)(MailData.unapply))

 def index = Action {

 def sendMail: Action[play.api.mvc.AnyContent] = Action { implicit  request =>
   mailForm.bindFromRequest.fold (
    formWithErrors => {
   mailData => {
    val mail = use[MailerPlugin].email
        mail.setSubject("Email sent using Scala")
        mail.send("Hello World")

5) Delete the code written in views/index.scala.html and write the following code to it

@(mailForm: Form[controllers.Application.MailData])

@import helper._

@main("Email Sending App") {

@helper.form(action = routes.Application.sendMail, 'id -> "MailForm") {

@inputText(mailForm("email"), '_label -> "Email")

<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Send Mail">

Note – For a Demo you can download the Demo App from

This entry was posted in Scala, Web and tagged , , , . Bookmark the permalink.

One Response to Adding an “Email sending” functionality in Play using Scala

  1. Pingback: A Non-blocking “Email sending” functionality in Scala | Knoldus

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s