如何使用激活器在 scala 和播放框架 (2.3.9) 中发送带有附件的电子邮件?

How to send email with attached file in scala and play framework (2.3.9) using activator?

好吧,我对 Scala 和 Play 框架完全陌生。我看到很多在 scala 中发送带有附件的邮件的例子,我也跟着他们,因为我在我的项目中使用激活器,我在项目的 conf 下找不到 play.plugin 而我只找到 application.conf。任何人都可以给我一份完整的文档或任何 link 的完整参考标准,逐步学习它们用于邮件程序插件。提前谢谢朋友。请完整参考,因为我很着急,请帮助我。

下面 link 我提到了:



https://gist.github.com/mariussoutier/3436111
https://github.com/playframework/play-mailer

请给我一个 link 示例代码以便完全理解或你的任何文档

我尝试使用 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.x 而您的应用程序基于 Play 2。3.x。

如插件的documentation中所写:

For Play 2.3.x please read the README on the 2.x branch.

您不能使用 @Inject。 Scala 中上述 link 的示例代码:

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)

您已拥有开始发送电子邮件所需的一切。

编辑 play.plugins

您需要自己创建文件 conf/play.plugins 并将其放入其中:

1500:play.api.libs.mailer.CommonsMailerPlugin