dmurvihill / courier   3.2.0

MIT License GitHub

send electronic mail with scala

Scala versions: 3.x 2.13 2.12 2.11 2.10


Maven Central

deliver electronic mail with scala from the future



Via the copy and paste method

libraryDependencies += "com.github.daddykotex" %% "courier" % "3.2.0"

3.2.0 supports scala 2.11 to 3.1

Note: Scala3 (or Dotty) is supported.

  • 3.0.0-RC1 for dotty: 0.27.0-RC1
  • 3.0.0-M1 for dotty: 3.0.0-M1
  • 3.0.0-M2 for dotty: 3.0.0-M2
  • 3.0.1 scala 3: 3.0.1
  • 3.1.9 scala 3: 3.1.0


deliver electronic mail via gmail

import courier._, Defaults._
import scala.util._
val mailer = Mailer("", 587)
               .as("[email protected]", "p@$$w3rd")
mailer(Envelope.from("you" `@` "")
        .to("mom" `@` "")
        .cc("dad" `@` "")
        .subject("miss you")
        .content(Text("hi mom"))).onComplete {
          case Success(_) => println("message delivered")
          case Failure(_) => println("delivery failed")

mailer(Envelope.from("you" `@` "")
         .to("boss" `@` "")
         .subject("tps report")
           .html("<html><body><h1>IT'S IMPORTANT</h1></body></html>")))
           .onComplete {
             case Success(_) => println("delivered report")
             case Failure(_) => println("delivery failed")

If using SSL/TLS instead of STARTTLS, substitute .startTls(true) with .ssl(true) when setting up the Mailer.


Courier supports sending S/MIME signed email through its optional dependencies on the Bouncycastle cryptography libraries. It does not yet support sending encrypted email.

Make sure the Mailer is instantiated with a signer, and then wrap your message in a Signed() object.

import courier._

val certificate: X509Certificate = ???
val privateKey: PrivateKey = ???
val trustChain: Set[X509Certificate] = ???

val signer = Signer(privateKey, certificate, trustChain)
val mailer = Mailer("", 587)
               .as("[email protected]", "p@$$w3rd")
val envelope = Envelope
        .from("mr_pink" `@` "")
        .to("mr_white" `@` "")
        .subject("the jewelry store")
        .content(Signed(Text("For all I know, you're the rat.")))



Since courier is based on JavaMail, you can use Mock JavaMail to execute your tests. Simply add the following to your build.sbt:

libraryDependencies += "org.jvnet.mock-javamail" % "mock-javamail" % "1.9" % "test"

With this library, you should, given a little bit of boilerplate, be able to set a test against a mocked Mailbox. This repo contains an example.

(C) Doug Tangren (softprops) and others, 2013-2018