Last active
August 29, 2015 14:13
-
-
Save divarvel/7938a7bd8c6a8d0b925f to your computer and use it in GitHub Desktop.
Mailjet + Play mailer plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using the play-mailer plugin <https://github.com/playframework/play-mailer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
smtp { | |
host=in-v3.mailjet.com | |
port=587 | |
tls=true | |
user="<user>" | |
password="<key>" | |
from="email@example.com" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.Play.current | |
import scala.concurrent.duration._ | |
import play.api.libs.concurrent.Akka | |
import play.api.libs.concurrent.Execution.Implicits._ | |
import play.api.Logger | |
import play.api.libs.mailer._ | |
object email { | |
val senderAddress = ("name", "email@example.com") | |
def sendEmail(name: String, emailAddress: String, subject: String, text: String, bcc: List[String] = Nil) = { | |
Logger.info(s"Scheduling email to $name <$emailAddress> ($subject)") | |
Akka.system.scheduler.scheduleOnce(0.seconds) { | |
val (fromName, fromAddress) = senderAddress | |
val email = Email( | |
subject = subject, | |
from = s"$fromName <$fromAddress>", | |
to = Seq(s"$name <$emailAddress>"), | |
bodyText = Some(text), | |
bcc = bcc | |
) | |
MailerPlugin.send(email) | |
Logger.info(s"Email sent to $name <$emailAddress> ($subject)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment