我有一个Maven项目,使用JSF 2.2,Tomcat 7和使用Apache Commons
发送电子邮件。org.apache.commons.mail.EmailException:将电子邮件发送到以下服务器失败:smtp.gmail.com:465
这里是我的代码
try {
// Create the email message
HtmlEmail email = new HtmlEmail();
email.setSmtpPort(465); //email.setSslSmtpPort("465");
email.setSSLOnConnect(true);
email.setHostName("smtp.gmail.com");
email.addTo("[email protected]", "test");
email.setFrom(getEmail(), getName());
email.setSubject(getSubject());
email.setHtmlMsg("<html>Test</html>"); // set the html message
email.setTextMsg(getText());// set the alternative message
email.send();// send the email
} catch (EmailException e) {
logger.error("Exception sending email: ", e);
} catch (Exception ex) {
logger.error("Exception sending email: ", ex);
}
当我试图给Tomcat 7运行的代码,我得到了以下异常:
org.apache.commons.mail.EmailException:发送电子邮件向 以下服务器失败:smtp.gmail.com:465
标准javax.mail API与HtmlEmail没有任何关系。它属于Apache Commons。 – Tiny