Mail-plugin

Play Framework 2 mail plugin

This project is maintained by mcveat

A Play 2.x plugin providing a scala wrapper to simple-java-mail

Installation

As ivy artifact

To your Build.scala add:

   resolvers += (
        Resolver.url("mcveat.github.com", url("http://mcveat.github.com/releases"))(Resolver.ivyStylePatterns)
    )

and "play.modules.mail" %% "play2-mail-plugin" % "0.6" as a dependency.

As a binary

Checkout the project, build it from the sources with sbt package command. Then either:

As a Git submodule

You can add it as a submodule of your play project. Checkout the project in modules/mail-plugin, then do git submodule add

In your project Build.scala add the dependency to the plugin :

    val mailPlugin = Project("mailPlugin", file("modules/mail-plugin"))
    val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA)
                .dependsOn(mailPlugin)

Usage

    import mail._
    import Mail._

    def sendMail = Action.async { request =>
        val attachment = Source.fromBytes("Ninja should wear black".toCharArray.map(_.toByte))
        val result = Mail()
            .from("sender", "sender@example.com")
            .to("receiver", "receiver@example.com")
            .replyTo("ninja master", "master@ninja.com")
            .withSubject("A subject")
            .withText("body")
            .withAttachments(Attachment("ninja code", attachment, "text/plain")
            .send()
        result.flatMap { _ => Ok("It works") }
    }

Mail class utilizes statically typed builder pattern, so send() method is not available before sender, receiver, subject and message body (either text or html) is set.

You can check this plugin scaladoc too.

Configuration

In application.conf :

    #put this setting in you want to mock the mail server in development
    mail.mock=true

    #smtp server settings
    smtp.host=smtp.server.com
    smtp.port=25
    smtp.username=
    smtp.password=
    smtp.transport=

Supported transports: SMTP_PLAIN (default), SMTP_SSL, SMTP_TLS

Changelog

version 0.6

scaladoc

version 0.5

version 0.4

version 0.3

version 0.2.1

version 0.2

scaladoc

version 0.1

scaladoc