Giter VIP home page Giter VIP logo

courier's Introduction

courier

Maven Central

deliver electronic mail with scala from the future

courier

install

Via the copy and paste method

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

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

courier's People

Contributors

softprops avatar daddykotex avatar danielgratzl avatar dmurvihill avatar frosner avatar tzeman77 avatar aduprat avatar christopherdavenport avatar astorije avatar mikeokner avatar phile314-fh avatar rleibman avatar atanana avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.