0

I have a web application running on Payara 5 and when I try to send an email it gives the following error:

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)
....

But when I run the method manually it works. The code is below

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();
}
  • There must be a stacktrace coming with this error. Please [edit] your question and include it. –  Jun 07 '19 at 15:04
  • There have been some other questions here related to email using SSL on Payara Server. I suspect this is a JDK configuration problem, perhaps related to how Payara Server is configuring the JDK. This error is a bit different, but it might be related. – Bill Shannon Jun 07 '19 at 18:33
  • 1
    If you are using Java EE and Payara you should make use of the JavaMail specification and define the Mail resources within the Payar application server and inject it to your code. This blog post might help you: https://rieckpil.de/howto-send-emails-with-java-ee-using-payara/ – rieckpil Jul 11 '19 at 11:01

0 Answers0