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

问题描述 投票:0回答:1

我试图通过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("[email protected]");
email.addTo("[email protected]");
email.setSubject("New Pending User");
email.setMsg("Hey this is a test");
Mail.send(email);

我正在使用Mailgun发送我的电子邮件,这似乎不是该配置的问题。在分离现有的,正常运行的应用程序并正确发送电子邮件之后,我遇到了这个错误。

出于这个原因,ClassCastException没有多大意义,因为我使用与现有应用程序相同的架构和html表单样式。是什么赋予了?

java email playframework
1个回答
0
投票

将您的邮件jar更新为1.5.x版本。此版本中已解决此错误

© www.soinside.com 2019 - 2024. All rights reserved.