play-mailer with play-scala 2.6

862 views
Skip to first unread message

Frederic Noyer

unread,
Jul 25, 2017, 5:10:08 PM7/25/17
to Play Framework
Dear All,

I am interested in building a sample web app in play-scala to understand the mechanism of mailing process.
In order to accomplished this I have been redirected to https://github.com/playframework/play-mailer
I have certainly misunderstood how to do it as nothing is compiling.
 
None tries have been successfull.
I have spent hours and hours browsing the web trying solutions and no result.
 
 
my SBT file
 
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._"
 
have so far edited the application.conf

# Mailer
# ~~~~~
play.mailer {
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.File
import org.apache.commons.mail.EmailAttachment
import javax.inject.Inject
 
class MailerService @Inject() (mailerClient: MailerClient) {
 
def sendEmail = {
val cid = "1234"
val email = Email(
"Simple email",
"Mister FROM <fr...@email.com>",
Seq("Miss TO <t...@email.com>"),
// adds attachment
attachments = Seq(
AttachmentFile("attachment.pdf", new File("/some/path/attachment.pdf")),
// adds inline attachment from byte array
AttachmentData("data.txt", "data".getBytes, "text/plain", Some("Simple data"), Some(EmailAttachment.INLINE)),
// adds cid attachment
AttachmentFile("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 controllers
 
import javax.inject.Provider
 
import play.api.libs.mailer.SMTPConfiguration
import play.api.{Configuration, Environment}
import play.api.inject.Module
 
class CustomSMTPConfigurationProvider extends Provider[SMTPConfiguration] {
override def get() = new SMTPConfiguration("typesafe.org", 1234)
}
 
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
Auto Generated Inline Image 1
Auto Generated Inline Image 2

Justin du coeur

unread,
Jul 25, 2017, 5:34:53 PM7/25/17
to play-fr...@googlegroups.com
As a rule of thumb, anything named -SNAPSHOT is pretty dangerous to use.  The page suggests that 6.0.0 is properly released -- try switching to that.  (That is, just remove the -SNAPSHOT and see if that works.)

--
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.

Reply all
Reply to author
Forward
0 new messages