在Payara 5中使用Web应用程序发送电子邮件

时间:2019-06-07 13:10:07

标签: java javamail payara apache-commons-email

我有一个运行在Payara 5上的Web应用程序,当我尝试发送电子邮件时,出现以下错误:

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1138)
at org.apache.commons.mail.Email.send(Email.java:1163)
at coclient.relatorio.RelChamada.enviarPeloGmail(RelChamada.java:177)
...
Caused by: java.lang.NoSuchFieldError: isEC
...
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2175)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
at javax.mail.Service.connect(Service.java:388)
...
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1128)
....

但是当我手动运行该方法时,它可以工作。代码在下面

public String enviarPeloGmail() {
try {
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(587);
//email.setSslSmtpPort("587");
email.setAuthenticator(new DefaultAuthenticator("remetente@gmail.com", "senha_remetente"));
email.setSSL(true);
email.setTLS(true);

email.setFrom("remetente@gmail.com");
email.setSubject("ENVIO DE EMAIL TESTE PELO SISTEMA");
email.setHtmlMsg("ESTOU MANDANDO EMAIL PELA CONTA DO GMAIL PELO SISTEMA");
email.addTo("destinatario@gmail.com");
email.send();

} catch (EmailException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

public static void main(String[] args) {
RelChamada r = new RelChamada();
r.enviarPeloGmail();
}

0 个答案:

没有答案