【问题标题】:NoSuchElementException in Play Framework while sending email?发送电子邮件时 Play Framework 中出现 NoSuchElementException?
【发布时间】:2015-09-30 08:46:59
【问题描述】:

下面,我粘贴了用于发送带有附件的邮件的代码。我没有在我的代码中遗漏什么,但我在我的 Web 应用程序中得到了 NoSuchElementException。谁能告诉我缺少什么或服务器部分有问题?我是否必须在我的代码项目中添加 apache 或任何服务器许可证。

下面是我的代码:

val email = Email(
  "Simple email",
  "Mister FROM <vignesh.gopal@hubino.com>",
  Seq("Miss TO <ibrahim.sultan@hubino.com>"),
  attachments = Seq(
    AttachmentFile("leak.txt", new File("E:/oui_mem_leak.txt")),
    AttachmentData("data.txt", "data".getBytes, "text/plain", Some("Simple data"), Some(EmailAttachment.INLINE))), 
  bodyText = Some("A text message"),
  bodyHtml = Some("<html><body><p>An <b>html</b> message</p></body></html>")
)
println("email contents: " + email)
MailerPlugin.send(email)

application.conf

smtp.host  = localhost
smtp.port  = 9000
smtp.ssl   = false
smtp.tls   = false
smtp.debug = false
smtp.mock  = false

build.sbt

  "org.apache.commons" % "commons-email" % "1.3.3",
  "com.typesafe.play" %% "play-mailer" % "2.4.1"

例外:

! @6nj6i1d36 - Internal server error, for (GET) [/stores/algo/file/download] ->

play.api.Application$$anon$1: Execution exception[[NoSuchElementException: None
get]]
        at play.api.Application$class.handleError(Application.scala:296) ~[play
2.11-2.3.9.jar:2.3.9]
        at play.api.DefaultApplication.handleError(Application.scala:402) [play
2.11-2.3.9.jar:2.3.9]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonf
n$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205) [play_2.11-2.3.9.ja
:2.3.9]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonf
n$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202) [play_2.11-2.3.9.ja
:2.3.9]
        at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.
cala:36) [scala-library-2.11.6.jar:na]
Caused by: java.util.NoSuchElementException: None.get
        at scala.None$.get(Option.scala:347) ~[scala-library-2.11.6.jar:na]
        at scala.None$.get(Option.scala:345) ~[scala-library-2.11.6.jar:na]
        at play.api.libs.mailer.MailerPlugin$.send(MailerPlugin.scala:25) ~[pla
-mailer_2.11-2.4.1.jar:2.4.1]

【问题讨论】:

  • 谁能给我一个解决上述异常的方法,拜托了。我被困了一整天
  • 如果您使用的是 play 2.4,那么实现已经改变。参考github.com/playframework/play-mailer
  • @Bhavya 感谢 Bhavya,不知何故我找到了解决问题的方法。也感谢您的努力。
  • @Vicky 请在这里分享您的解决方案
  • 我也遇到了这个错误,不知道为什么..

标签: scala email playframework nosuchelementexception


【解决方案1】:

看起来配置错误。你配置了吗

1500:play.api.libs.mailer.CommonsMailerPlugin 

在你的 conf/play.plugins 中?

【讨论】:

  • 是的,我的 play.plugins 中有它们
【解决方案2】:

这一切都是因为我们使用了过时的插件版本。查看@Bhavya 的评论

插件的最新版本在这里:https://github.com/playframework/play-mailer

【讨论】:

    猜你喜欢
    • 2015-12-24
    • 2011-10-31
    • 2015-09-13
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    相关资源
    最近更新 更多