Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 06, 2012
Arthur Gautier Indent build.sbt dafcb13
Arthur Gautier Split code in different files
Rewrite imports
49a582b
Arthur Gautier Merge branch 'master' of https://github.com/taraxe/mail-plugin
Conflicts:
	src/main/scala/Mail.scala
3f16733
View
12 build.sbt
@@ -9,9 +9,9 @@ resolvers += "Typesafe repository snapshots" at "http://repo.typesafe.com/typesa
resolvers += "Typesafe repository releases" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
-"org.codemonkey.simplejavamail" % "simple-java-mail" % "2.0",
-"play" %% "play" % "2.0-SNAPSHOT",
-"play" %% "play-test" % "2.0-SNAPSHOT",
-"org.specs2" %% "specs2" % "1.7.1" % "test",
-"junit" % "junit" % "4.8" % "test"
- )
+ "org.codemonkey.simplejavamail" % "simple-java-mail" % "2.0",
+ "play" %% "play" % "2.0-SNAPSHOT",
+ "play" %% "play-test" % "2.0-SNAPSHOT",
+ "org.specs2" %% "specs2" % "1.7.1" % "test",
+ "junit" % "junit" % "4.8" % "test"
+)
View
74 src/main/scala/Mail.scala
@@ -1,16 +1,18 @@
-
package play.modules.mail
-import play.api._
-import play.api.libs.concurrent._
-import templates.Html
+import play.modules.mail.MailBuilder.Mail
+
+import play.api.{Logger, Plugin, Application, PlayException}
+import play.api.libs.concurrent.{akkaToPlay, Promise}
+
import play.libs.Akka
-import akka.actor.{Props, Actor}
+
import akka.pattern.ask
-import akka.util.duration._
-import org.codemonkey.simplejavamail.{MailException, Email, Mailer}
+import akka.util.Duration
+import akka.util.Timeout
+
+import org.codemonkey.simplejavamail.{Email, Mailer}
import java.util.concurrent.Callable
-import play.modules.mail.MailBuilder.Mail
/**
@@ -50,7 +52,7 @@ object MailPlugin {
private def sendMessage(msg:Email)(implicit app:Application):Promise[Boolean] = {
val mailer = helper.mailer
import akka.util.Timeout
- implicit val timeout = Timeout(5 second)
+ implicit val timeout = Timeout(Duration(5, "seconds"))
(MailWorker.ref ? (msg,mailer)).mapTo[Boolean].asPromise
}
@@ -60,60 +62,6 @@ object MailPlugin {
}
}
-object MailBuilder {
-
-
- import javax.mail.Message.RecipientType
- sealed case class Recipient(t:RecipientType)
- case class To() extends Recipient(RecipientType.TO)
- case class Bcc() extends Recipient(RecipientType.BCC)
- case class CC() extends Recipient(RecipientType.CC)
-
- object Mail {
- def apply() = new Mail()
- }
-
- case class Mail(_from:Option[(String, String)] = None, _subject:Option[String] = None, _to:List[(String, String, Recipient)] = Nil, _text:Option[String] = None, _html:Option[Html] = None) {
- def from(f:(String, String)):Mail = this.copy(_from = Some(f))
- def subject(s:String):Mail = this.copy(_subject = Some(s))
- def to(t:List[(String, String, Recipient)]):Mail = this.copy(_to = t)
- def text(t:String):Mail = this.copy(_text = Some(t))
- def html(h:Html):Mail = this.copy(_html = Some(h))
-
- def toEmail:Email = {
- val email = new Email();
- this._from.map(f => email.setFromAddress(f._1,f._2))
- this._subject.map(s => email.setSubject(s))
- this._to.foreach(t => email.addRecipient(t._1,t._2,t._3.t))
- this._text.map(s => email.setText(s))
- this._html.map(h => email.setTextHTML(h.toString))
-
- email
- }
- }
-}
-
-class MailWorker extends Actor {
- def receive = {
- case (email:Email,mailer:Mailer) => {
- try {
- mailer.sendMail(email)
- Logger.info("MailPlugin: email sent")
- sender ! true
- } catch {
- case e:MailException => {
- Logger.error("MailPlugin error:"+e.getMessage)
- sender ! false
- }
- }
- }
- }
-}
-
-object MailWorker {
- val ref = Akka.system.actorOf(Props[MailWorker])
-}
-
private[mail] case class MailHelper(host:String=MailPlugin.DEFAULT_HOST, port:Int=MailPlugin.DEFAULT_PORT, username:String ="", password:String ="") {
def mailer = new Mailer(host, port, username, password)
}
View
36 src/main/scala/MailBuilder.scala
@@ -0,0 +1,36 @@
+package play.modules.mail
+
+import play.api.templates.Html
+
+
+object MailBuilder {
+ import javax.mail.Message.RecipientType
+ sealed case class Recipient(t:RecipientType)
+ case class To() extends Recipient(RecipientType.TO)
+ case class Bcc() extends Recipient(RecipientType.BCC)
+ case class CC() extends Recipient(RecipientType.CC)
+
+ object Mail {
+ def apply():Mail = new Mail()
+ }
+
+ case class Mail(_from:Option[(String, String)] = None, _subject:Option[String] = None, _to:List[(String, String, Recipient)] = Nil, _text:Option[String] = None, _html:Option[Html] = None) {
+ def from(f:(String, String)):Mail = this.copy(_from = Some(f))
+ def subject(s:String):Mail = this.copy(_subject = Some(s))
+ def to(t:List[(String, String, Recipient)]):Mail = this.copy(_to = t)
+ def text(t:String):Mail = this.copy(_text = Some(t))
+ def html(h:Html):Mail = this.copy(_html = Some(h))
+
+ def toEmail:Email = {
+ val email = new Email();
+ this._from.map(f => email.setFromAddress(f._1,f._2))
+ this._subject.map(s => email.setSubject(s))
+ this._to.foreach(t => email.addRecipient(t._1,t._2,t._3.t))
+ this._text.map(s => email.setText(s))
+ this._html.map(h => email.setTextHTML(h.toString))
+ email
+ }
+ }
+}
+
+// vim: set ts=2 sw=2 ft=scala et:
View
32 src/main/scala/MailWorker.scala
@@ -0,0 +1,32 @@
+package play.modules.mail
+
+import play.api.Logger
+import play.libs.Akka
+
+import akka.actor.{Actor, Props}
+
+import org.codemonkey.simplejavamail.{MailException, Email, Mailer}
+
+object MailWorker {
+ val ref = Akka.system.actorOf(Props[MailWorker])
+}
+
+class MailWorker extends Actor {
+ def receive = {
+ case (email:Email,mailer:Mailer) => {
+ try {
+ mailer.sendMail(email)
+ Logger.info("MailPlugin: email sent")
+ sender ! true
+ } catch {
+ case e:MailException => {
+ Logger.error("MailPlugin error:"+e.getMessage)
+ sender ! false
+ }
+ }
+ }
+ }
+}
+
+
+// vim: set ts=2 sw=2 ft=scala et:

No commit comments for this range

Something went wrong with that request. Please try again.