Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

dúvidas no envio de e-mail com SimpleEmail

Olá Estou com dificuldades em encontrar a solução para o envio de e-mail usando commons mail.

o código está assim: no pom.xml pra essa parte do e-mail:

    <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-email</artifactId>
            <version>1.3.1</version>
    </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.6.0</version>
    </dependency>  

na classe de envio do e-mail

    public void enviaEmail() throws EmailException{
        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("marciel.dosanjos@gmail.com", "password"));
        email.setStartTLSEnabled(true);
        email.setFrom("marciel.dosanjos@gmail.com");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("marciel_100@hotmail.com");
        email.send();
    }

Mas sempre recebo como resposta esse log:

HTTP Status 500 - org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
type Exception report

message org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
    br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:122)
root cause

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
    org.apache.commons.mail.Email.sendMimeMessage(Email.java:1401)
    org.apache.commons.mail.Email.send(Email.java:1428)
    br.com.caelum.vraptor.controller.NoticiaController.enviaEmail(NoticiaController.java:95)
    br.com.caelum.vraptor.controller.NoticiaController$Proxy$_$$_WeldClientProxy.enviaEmail(Unknown Source)
.
.
root cause

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
    javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2196)
.
.
root cause

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
.
.
root cause

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
.
.
root cause

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
    sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)

Pesquisando, a principio encontrei falando que falta certificado. Então coloquei os certificados do gmail e do hotmail no cacerts. Mas mesmo assim essa falha continua. Tentei alternar entre TLS (porta 587) e SSL (portas 486 e 25)... mas mesmo assim continua dando essa mensagem. Encontrei outas jeitos de implementação, variações dessa ai, mas continua essa mesma falha.

1 resposta
solução!

deu certo agora.