我在 Wildfly 8 中成功使用了来自 org.apache.commons.mail.SimpleEmail 的 SimpleEmail。现在,我迁移到 Wildfy 9,SimpleEmail 每次都会引发连接异常。
email.send()
在下面的代码中引发了异常:
try
{
Email email = new SimpleEmail();
email.setHostName("mail.gmx.net");
email.setAuthenticator(new DefaultAuthenticator("sender@gmx.ch", "password"));
email.setSSLOnConnect(true);
email.setFrom("sender@gmx.ch");
email.setCharset(org.apache.commons.mail.EmailConstants.UTF_8);
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("receiver@gmx.ch");
email.send();
}
异常跟踪:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.gmx.net:465
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
at org.apache.commons.mail.Email.send(Email.java:1448)
...
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: mail.gmx.net, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2042)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
... 53 more
有人知道我需要在哪里搜索问题吗?