Git Product home page Git Product logo

courier's Introduction

courier

deliver electronic mail with scala from the future

courier

install

Via the copy and paste method

resolvers += "lightshed-maven" at "http://dl.bintray.com/content/lightshed/maven"

libraryDependencies += "ch.lightshed" %% "courier" % "0.1.4"

Note. If you are a bintray-sbt user you can optionally specify the resolver as

resolvers += Resolver.bintrayRepo("lightshed", "maven")

usage

deliver electronic mail via gmail

import courier._, Defaults._
val mailer = Mailer("smtp.gmail.com", 587)
               .auth(true)
               .as("[email protected]", "p@$$w3rd")
               .startTtls(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")
           }

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"

Having this in your test dependencies will automatically enable Mock JavaMail during tests. You can then test for email sends, etc.

import courier._
import org.specs2.mutable.Specification
import scala.concurrent.duration._

// Need NoTimeConversions to prevent conflict with scala.concurrent.duration._
class MailSpec extends Specification with NoTimeConversions {
  "the mailer" should {
  	"send an email" in {
  	  val mailer = Mailer("localhost", 25)()
  	  val future = mailer(Envelope.from("[email protected]".addr)
          	.to("[email protected]".addr)
          	.cc("[email protected]".addr)
          	.subject("miss you")
          	.content(Text("hi mom")))

          Await.ready(future, 5.seconds)
          val momsInbox = Mailbox.get("[email protected]")
          momsInbox.size === 1
          val momsMsg = momsInbox.get(0)
          momsMsg.getContent === "hi mom"
          momsMsg.getSubject === "miss you"
        }       	
  	}
  }
}        

Here is an excellent article on using Mock JavaMail.

Doug Tangren (softprops) 2013

courier's People

Contributors

astorije avatar christopherdavenport avatar danielgratzl avatar frosner avatar phile314-fh avatar rleibman avatar softprops avatar tzeman77 avatar

Watchers

 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.