scala-mailer-core


License

License

MIT
Categories

Categories

Scala Languages Net
GroupId

GroupId

net.kaliber
ArtifactId

ArtifactId

scala-mailer-core_2.11
Last Version

Last Version

6.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

scala-mailer-core
scala-mailer-core
Project URL

Project URL

https://github.com/kaliber-scala/scala-mailer
Project Organization

Project Organization

net.kaliber
Source Code Management

Source Code Management

https://github.com/kaliber-scala/scala-mailer

Download scala-mailer-core_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/net.kaliber/scala-mailer-core_2.11/ -->
<dependency>
    <groupId>net.kaliber</groupId>
    <artifactId>scala-mailer-core_2.11</artifactId>
    <version>6.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.kaliber/scala-mailer-core_2.11/
implementation 'net.kaliber:scala-mailer-core_2.11:6.0.1'
// https://jarcasting.com/artifacts/net.kaliber/scala-mailer-core_2.11/
implementation ("net.kaliber:scala-mailer-core_2.11:6.0.1")
'net.kaliber:scala-mailer-core_2.11:jar:6.0.1'
<dependency org="net.kaliber" name="scala-mailer-core_2.11" rev="6.0.1">
  <artifact name="scala-mailer-core_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.kaliber', module='scala-mailer-core_2.11', version='6.0.1')
)
libraryDependencies += "net.kaliber" % "scala-mailer-core_2.11" % "6.0.1"
[net.kaliber/scala-mailer-core_2.11 "6.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8
javax.mail : mail jar 1.4.7

provided (1)

Group / Artifact Type Version
com.typesafe : config jar 1.3.1

test (2)

Group / Artifact Type Version
org.specs2 : specs2-core_2.11 jar 3.6.2
org.jvnet.mock-javamail : mock-javamail jar 1.9

Project Modules

There are no modules declared in this project.

This repository is no longer maintained

Just create a fork, if you want I can list it here.


Scala mailer module with support for Play 2.5.x

Scala wrapper around java mail which allows you to send emails. The default configuration options exposed in Configuration work using Amazon SES SMTP.

Installation

You can add the scala-mailer to SBT, by adding the following to your build.sbt file

  libraryDependencies += "net.kaliber" %% "play-mailer" % "6.0.0"

Usage

Creating an email

  import net.kaliber.mailer._

  Email(
    subject = "Test mail",
    from = EmailAddress("Erik Westra sender", "[email protected]"),
    text = "text",
    htmlText = "htmlText",
    replyTo = None,
    recipients = List(Recipient(
      RecipientType.TO, EmailAddress("Erik Westra recipient", "[email protected]"))),
    attachments = Seq.empty)

  // a more convenient way to create an email
  val email = Email(
    subject = "Test mail",
    from = EmailAddress("Erik Westra sender", "[email protected]"),
    text = "text",
    htmlText = "htmlText")
    .to("Erik Westra TO", "[email protected]")
    .cc("Erik Westra CC", "[email protected]")
    .bcc("Erik Westra BCC", "[email protected]")
    .replyTo("Erik Westra REPLY_TO", "[email protected]")
    .withAttachments(
      Attachment("attachment1", Array[Byte](0, 1), "application/octet-stream"),
      Attachment("attachment2", Array[Byte](0, 1), "application/octet-stream", Disposition.Inline))

Sending an email asynchronously

  import net.kaliber.mailer._

  val mailerSettings = MailerSettings(
    protocol = Some("smtps"),
    host = "email-smtp.us-east-1.amazonaws.com",
    port = "465",
    failTo = "[email protected]",
    auth = Some(true),
    username = Some("Smtp username as generated by Amazon"),
    password = Some("Smtp password")
    
  val result = new Mailer(Session.fromSetting(mailerSettings)).sendEmail(email)
    
  result
    .map { unit =>
      // mail sent successfully
    }
    .recover {
      case SendEmailException(email, cause) =>
      // problem sending email
      case SendEmailTransportCloseException(result, cause) =>
      // problem closing connection
    }

Sending multiple emails asynchronously

  import net.kaliber.mailer._
  
  val mailerSettings = MailerSettings(
    protocol = Some("smtps"),
    host = "email-smtp.us-east-1.amazonaws.com",
    port = "465",
    failTo = "[email protected]",
    auth = Some(true),
    username = Some("Smtp username as generated by Amazon"),
    password = Some("Smtp password")
      
  val result = new Mailer(Session.fromSetting(mailerSettings)).sendEmails(email1, email2)

  result
    .map { results =>
      results.foreach {
        case Success(_) =>
          //mail sent successfully
        case Failure(SendEmailException(email, cause)) =>
          //failed to send email, cause provides more information
      }
    }
    .recover {
      case SendEmailException(email, cause) =>
        // problem sending email
      case SendEmailTransportCloseException(result, cause) =>
        // problem closing connection
    }

Play Configuration

application.conf should contain the following information:

mail.failTo="[email protected]"

mail.host=email-smtp.us-east-1.amazonaws.com
mail.port=465

#only required if mail.auth=true (the default)
mail.username="Smtp username as generated by Amazon"
mail.password="Smtp password"

application.conf can additionally contain the following information:

#default is smtps
mail.transport.protocol=smtp

#default is true
mail.auth=false

Usage with Play configuration

Sending an email asynchronously

  import net.kaliber.mailer._
  import net.kaliber.play.mailer.Session

  val result = new Mailer(Session.fromConfiguration(configuration)).sendEmail(email)
  
  result
    .map { unit =>
      // mail sent successfully
    }
    .recover {
      case SendEmailException(email, cause) =>
      // problem sending email
      case SendEmailTransportCloseException(result, cause) =>
      // problem closing connection
    }

Sending multiple emails asynchronously

  import net.kaliber.mailer._
  import net.kaliber.play.mailer.Session

  val results = new Mailer(Session.fromConfiguration(configuration)).sendEmails(Seq(email1, email2))
  
  results
    .map { results =>
      results.foreach {
        case Success(_) =>
        //mail sent successfully
        case Failure(SendEmailException(email, cause)) =>
        //failed to send email, cause provides more information
      }
    }
    .recover {
      case SendEmailException(email, cause) =>
      // problem sending email
      case SendEmailTransportCloseException(result, cause) =>
      // problem closing connection
    }
net.kaliber

Kaliber Scala

Open Source Scala Libraries

Versions

Version
6.0.1
6.0.0