courier

deliver electronic mail with scala

License

License

MIT
GroupId

GroupId

com.github.daddykotex
ArtifactId

ArtifactId

courier_0.27
Last Version

Last Version

3.0.0-RC1
Release Date

Release Date

Type

Type

jar
Description

Description

courier
deliver electronic mail with scala
Project URL

Project URL

https://github.com/dmurvihill/courier
Project Organization

Project Organization

com.github.daddykotex
Source Code Management

Source Code Management

https://github.com/dmurvihill/courier

Download courier_0.27

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.daddykotex/courier_0.27/ -->
<dependency>
    <groupId>com.github.daddykotex</groupId>
    <artifactId>courier_0.27</artifactId>
    <version>3.0.0-RC1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.daddykotex/courier_0.27/
implementation 'com.github.daddykotex:courier_0.27:3.0.0-RC1'
// https://jarcasting.com/artifacts/com.github.daddykotex/courier_0.27/
implementation ("com.github.daddykotex:courier_0.27:3.0.0-RC1")
'com.github.daddykotex:courier_0.27:jar:3.0.0-RC1'
<dependency org="com.github.daddykotex" name="courier_0.27" rev="3.0.0-RC1">
  <artifact name="courier_0.27" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.daddykotex', module='courier_0.27', version='3.0.0-RC1')
)
libraryDependencies += "com.github.daddykotex" % "courier_0.27" % "3.0.0-RC1"
[com.github.daddykotex/courier_0.27 "3.0.0-RC1"]

Dependencies

compile (5)

Group / Artifact Type Version
ch.epfl.lamp : dotty-library_0.27 jar 0.27.0-RC1
com.sun.mail : javax.mail jar 1.6.2
javax.activation : activation jar 1.1.1
org.bouncycastle : bcpkix-jdk15on Optional jar 1.61
org.bouncycastle : bcmail-jdk15on Optional jar 1.61

test (3)

Group / Artifact Type Version
org.scalactic : scalactic_0.27 jar 3.2.2
org.scalatest : scalatest_0.27 jar 3.2.2
org.jvnet.mock-javamail : mock-javamail jar 1.9

Project Modules

There are no modules declared in this project.

courier

Maven Central

deliver electronic mail with scala from the future

courier

install

Via the copy and paste method

libraryDependencies += "com.github.daddykotex" %% "courier" % "3.0.0-M1"

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

usage

deliver electronic mail via gmail

import courier._, Defaults._
val mailer = Mailer("smtp.gmail.com", 587)
               .auth(true)
               .as("[email protected]", "p@$$w3rd")
               .startTls(true)()
mailer(Envelope.from("you" `@` "gmail.com")
        .to("mom" `@` "gmail.com")
        .cc("dad" `@` "gmail.com")
        .subject("miss you")
        .content(Text("hi mom"))).onSuccess {
          case _ => println("message delivered")
        }

mailer(Envelope.from("you" `@` "work.com")
         .to("boss" `@` "work.com")
         .subject("tps report")
         .content(Multipart()
           .attach(new java.io.File("tps.xls"))
           .html("<html><body><h1>IT'S IMPORTANT</h1></body></html>")))
           .onSuccess {
             case _ => println("delivered report")
           }

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

S/MIME

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._
import java.security.cert.X509Certificate
import java.security.PrivateKey

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

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

mailer(envelope)

testing

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

Versions

Version
3.0.0-RC1