Skip to content

techmag/play-mailer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This plugin provides a simple emailer.

Travis build status

Setup

Note
For Play 2.3.x please read the README on the 2.3.x branch.
  1. Add a library dependency on play-mailer:

    "com.typesafe.play" %% "play-mailer" % "{version}"

    See below for the version matrix.

  2. Configure the mailer in your conf/application.conf:

    smtp.host (mandatory)
    smtp.port (defaults to 25)
    smtp.ssl (defaults to no)
    smtp.tls (defaults to no)
    smtp.user (optional)
    smtp.password (optional)
    smtp.debug (defaults to no, to take effect you also need to set the log level to "DEBUG" for the application logger)
    smtp.mock (defaults to no, will only log all the email properties instead of sending an email)
    smtp.timeout (defaults to 60s)
    smtp.connectiontimeout (defaults to 60s)

Usage

Java

import play.libs.mailer.Email;
import play.libs.mailer.MailerClient;
import javax.inject.Inject;

public class MyComponent {
  @Inject MailerClient mailerClient;


  public void sendEmail() {
    Email email = new Email();
    email.setSubject("Simple email");
    email.setFrom("Mister FROM <[email protected]>");
    email.addTo("Miss TO <[email protected]>");
    // adds attachment
    email.addAttachment("attachment.pdf", new File("/some/path/attachment.pdf"));
    // adds inline attachment from byte array
    email.addAttachment("data.txt", "data".getBytes(), "text/plain", "Simple data", EmailAttachment.INLINE);
    // sends text, HTML or both...
    email.setBodyText("A text message");
    email.setBodyHtml("<html><body><p>An <b>html</b> message</p></body></html>");
    mailerClient.send(email);
  }
}

Scala

import play.api.libs.mailer._
import javax.inject.Inject

public class MyComponent @Inject() (mailerClient: MailerClient) {

  val email = Email(
    "Simple email",
    "Mister FROM <[email protected]>",
    Seq("Miss TO <[email protected]>"),
    // adds attachment
    attachments = Seq(
      AttachmentFile("attachment.pdf", new File("/some/path/attachment.pdf")),
      // adds inline attachment from byte array
      AttachmentData("data.txt", "data".getBytes, "text/plain", Some("Simple data"), Some(EmailAttachment.INLINE))
    ),
    // sends text, HTML or both...
    bodyText = Some("A text message"),
    bodyHtml = Some("<html><body><p>An <b>html</b> message</p></body></html>")
  )
  mailerClient.send(email)
}

Versioning

The Play Mailer plugin supports several different versions of Play.

Plugin version Play version

2.x

2.3.x

3.x (milestone)

2.4.x

Current Versions

For Play 2.3:

"com.typesafe.play" %% "play-mailer" % "2.4.1"

For Play 2.4 milestone:

"com.typesafe.play" %% "play-mailer" % "3.0.0-RC1"

Licence

This software is licensed under the Apache 2 license, quoted below.

Copyright 2012 Typesafe (http://www.typesafe.com).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Play mailer plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 78.6%
  • Java 21.4%