【发布时间】: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