无法使用Java / Play Mailer发送电子邮件

时间:2018-10-10 17:05:12

标签: java email playframework

我正在尝试通过Play Framework Mailer类发送电子邮件,但是我一直收到相同的ClassCastException。这是控制台输出:

-- Exception in thread "DataHandler.getInputStream" java.lang.ClassCastException: javax.mail.internet.MimeMultipart cannot be cast to java.lang.String
-- at org.apache.geronimo.mail.handlers.TextHandler.writeTo(TextHandler.java:143)
-- at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
-- at javax.activation.DataHandler$1.run(DataHandler.java:266)
-- at java.lang.Thread.run(Thread.java:748)
-- 16:48:06,606 ERROR ~
--
-- @79gebib82
-- The email has not been sent
--
-- Mail error
-- A mail error occurred : Error while sending email
--
-- play.exceptions.MailException: Error while sending email
-- at play.libs.Mail$1.call(Mail.java:193)
-- at play.libs.Mail$1.call(Mail.java:184)
-- at java.util.concurrent.FutureTask.run(FutureTask.java:262)
-- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
-- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
-- at java.lang.Thread.run(Thread.java:748)
-- Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mailgun.org:465
-- at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
-- at org.apache.commons.mail.Email.send(Email.java:1448)
-- at play.libs.Mail$1.call(Mail.java:190)
-- ... 5 more
-- Caused by: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Converting body of type text/html; charset=UTF-8 failed)
-- at javax.mail.Transport.send(Transport.java:163)
-- at javax.mail.Transport.send(Transport.java:48)
-- at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
-- ... 7 more
-- Caused by: javax.mail.MessagingException: Converting body of type text/html; charset=UTF-8 failed
-- at com.google.appengine.api.mail.stdimpl.GMTransport.convertAttachmentToString(GMTransport.java:368)
-- at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:217)
-- at javax.mail.Transport.send(Transport.java:95)
-- ... 9 more

这是我用来发送电子邮件的代码:

SimpleEmail email = new SimpleEmail();
email.setFrom("noreply@draftr.app");
email.addTo("signup@draftr.app");
email.setSubject("New Pending User");
email.setMsg("Hey this is a test");
Mail.send(email);

我正在使用Mailgun发送电子邮件,但这似乎与该配置无关。分支了一个现有的,功能正常的活动应用程序并正确发送电子邮件后,我遇到了此错误。

由于这个原因,ClassCastException没有多大意义,因为Im使用与现有应用程序相同的体系结构和html表单样式。有什么作用?

1 个答案:

答案 0 :(得分:0)

将您的邮件罐更新为1.5.x版本。该错误已在该版本中得到解决