如何在scala和play框架(2.3.9)中使用activator发送带有附件的电子邮件



嗯,我对Scala和Play框架完全陌生。我看到了很多在scala中发送带有附加文件的邮件的例子,我也跟着他们,因为我在我的项目中使用activator,我找不到play。在项目conf下的插件,而不是我发现只有application.conf。谁能给我一个完整的文件或任何链接与完整的参考标准一步一步学习他们的邮件插件。提前感谢朋友们。请完成参考,因为我赶时间,请帮助我的家伙。

下面的链接我提到了:

http://stackoverflow.com/questions/22765364/send-email-with-java-and-play-framework-2-2-2
http://stackoverflow.com/questions/10492858/sending-emails-in-playframework-2-0
https://gist.github.com/mariussoutier/3436111
https://github.com/playframework/play-mailer
http://stackoverflow.com/questions/30208339/play-framework-2-3-x-unable-to-send-emails-using-plugin-play-mailer

请给我一个示例代码的链接,以便完全理解或您的任何文件

我尝试使用playframework play-mailer,但我得到一些错误,如

[error] object inject is not a member of package javax
[error] import javax.inject.Inject
[error]              ^
[error] object MailerClient is not a member of package play.libs.mailer
[error] import play.libs.mailer.MailerClient;
[error]        ^
[error] not found: type MailerClient
[error] class MyComponent @Inject() (mailerClient: MailerClient)
[error]                                            ^
[error] not found: type Inject
[error] class MyComponent @Inject() (mailerClient: MailerClient)
[error]                    ^
[error] object play.libs.mailer.Email is not a value
[error]   val email = Email(
[error]               ^
[error] not found: value attachments
[error]     attachments = Seq(
[error]     ^
[error] not found: value bodyText
[error]     bodyText = Some("A text message"),
[error]     ^
[error] not found: value bodyHtml
[error]     bodyHtml = Some(s"""<html><body><p>An <b>html</b> message   with cid < img src="cid:$cid"></p></body></html>""")
[error]     ^
[error] not found: value mailerClient
[error]   mailerClient.send(email)

您正在使用Play 2.4插件。而你的应用程序是基于Play 2.3.x。

如插件文档中所写:

For Play 2.3。请阅读2上的自述文件。x分支。

不能使用@Inject。上面链接的Scala示例代码:

import play.api.libs.mailer._
val email = Email(
  "Simple email",
  "Mister FROM <from@email.com>",
  Seq("Miss TO <to@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))
  ),
  // sends text, HTML or both...
  bodyText = Some("A text message"),
  bodyHtml = Some("<html><body><p>An <b>html</b> message</p></body></html>")
)
MailerPlugin.send(email)

你有你需要开始发送电子邮件的一切。

EDIT for play.plugins

你需要自己创建文件conf/play.plugins,并把它放在里面:

1500:play.api.libs.mailer.CommonsMailerPlugin

相关内容

  • 没有找到相关文章

最新更新