Play framwork 2.0.4 发送电子邮件
安装
play 2.0.x:
在你的 dependencies (project/Build.scala)里增加
"com.typesafe" %% "play-plugins-mailer" % "2.0.4"
然后
在你的conf/play.plugins里增加
1500:com.typesafe.plugin.CommonsMailerPlugin
接着, 在你的 conf/application.conf里增加并完善如下配置
smtp.host (mandatory)
smtp.port (defaults to 25)
smtp.ssl (defaults to no)
smtp.tls (defaults to no)
smtp.user (optional)
smtp.password (optional)
java 里的配置
import com.typesafe.plugin.*;
MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
mail.setSubject("mailer");
mail.addRecipient("Peter Hausel Junior <noreply@email.com>","example@foo.com");
mail.addFrom("Peter Hausel <noreply@email.com>");
//sends html
mail.sendHtml("<html>html</html>" );
//sends text/text
mail.send( "text" );
//sends both text and html
mail.send( "text", "<html>html</html>");
scala里的配置
import com.typesafe.plugin._
val mail = use[MailerPlugin].email
mail.setSubject("mailer") www.zzzyk.com
mail.addRecipient("Peter Hausel Junior <noreply@email.com>","example@foo.com")
mail.addFrom("Peter Hausel <noreply@email.com>")
//sends html
mail.sendHtml("<html>html</html>" )
//sends text/text
mail.send( "text" )
//sends both text and html
mail.send( "text", "<html>html</html>")
使用[MailPlugin]需要一个抽象的play.api.Application,如果在你应用插件的地方没有你需要在当前的Application里添加如下内容:
import play.api.Play.current
补充:综合编程 , 其他综合 ,