sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
package br.com.alura.enviadorEmail;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.springframework.stereotype.Service;
@Service
public class EmailService {
public void enviar(String nome, String emailDestinatario){
try {
Email email = new SimpleEmail();
email.setHostName("smtp.gmail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("meuemail@gmail.com", "minhasenha"));
email.setSSLOnConnect(true);
email.setFrom("meuemail@gmail.com");
email.setSubject("ListaVIP da Carol!!!");
email.setMsg("Olá " + nome + ". Você acaba de ser convidado pelo ListaVIP.");
email.addTo(emailDestinatario);
email.send();
} catch (EmailException e) {
e.printStackTrace();
}
}
}