
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:
-
Add ”com.typesafe.play.plugins” %% “play-plugins-mailer” % “2.3.1” to libraryDependencies (build.sbt)
-
Add the following to application.conf:
Email config
smtp.host=smtp.gmail.com
smtp.port=465
smtp.ssl=yes
smtp.tls=yes
smtp.user="my_username@gmail.com"
smtp.password=my_password
If you use a ‘!’ in your smtp.password, put a ‘””’ round ‘!’ (as ‘!’ is a reserved character). Change your smtp.user (to your own email address).
- Create a new file conf/play.plugins:
1500:com.typesafe.plugin.CommonsMailerPlugin
- Add the following to routes:
GET /email controllers.Application.sendEmail
- Completely replace controllers/Application.scala (change the Recipient and From email addresses):
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 https://github.com/playframework/play-mailer