name := """play-scala-mailing"""
organization := "com.example"
version := "1.0-SNAPSHOT"
scalaVersion := "2.12.2"
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-mailer" % "6.0.0-SNAPSHOT"
)
lazy val root = (project in file(".")).enablePlugins(PlayJava)
// play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"
# Mailer# ~~~~~play.mailer { host="smtp.gmail.com" port=587 ssl=no tls=yes user="*******************@gmail.com" password="******************" debug=yes}play { modules { disabled += "play.api.libs.mailer.SMTPConfigurationModule" enabled += "controllers.CustomMailerConfigurationModule" }}I have created MailService.scala
import play.api.libs.mailer._import java.io.Fileimport org.apache.commons.mail.EmailAttachmentimport javax.inject.Injectclass MailerService @Inject() (mailerClient: MailerClient) {def sendEmail = {val cid = "1234"val email = Email("Simple email",// adds attachmentattachments = Seq(AttachmentFile("attachment.pdf", new File("/some/path/attachment.pdf")),// adds inline attachment from byte arrayAttachmentData("data.txt", "data".getBytes, "text/plain", Some("Simple data"), Some(EmailAttachment.INLINE)),// adds cid attachmentAttachmentFile("image.jpg", new File("/some/path/image.jpg"), contentId = Some(cid))),// sends text, HTML or both...bodyText = Some("A text message"),bodyHtml = Some(s"""<html><body><p>An <b>html</b> message with cid <img src="cid:$cid"></p></body></html>"""))mailerClient.send(email)}}
In Dynamic Configuration I have created a file CustomSMTPConfigurationProvider.scala containing
package controllersimport javax.inject.Providerimport play.api.libs.mailer.SMTPConfigurationimport play.api.{Configuration, Environment}import play.api.inject.Moduleclass CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] {}class CustomMailerConfigurationModule extends Module {def bindings(environment: Environment, configuration: Configuration) = Seq(bind[SMTPConfiguration].toProvider[CustomSMTPConfigurationProvider])}
I am not sure that i had to include the folder play-mailer-guice and play-mailer into my project. Thi is the structure of my project
I have started in play-scala last year and I believe in this framework.
With that said I also think there is a lot of change and sometimes no clear example.
Is there anyone out there with a clear example that can help me? What am I doing wrong?
Version information:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.2")
sbt.version=0.13.15
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.8.0")
Thanks in advanced for your help.
Kind regards.
Frédéric Noyer
--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/60df9e0a-42a4-4e06-be98-ef5746fd778a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.