我有一個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