0
Good morning. I’m having trouble sending an email using Javamail.
Returns the following exception:
(javax.mail.SendFailedException)javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
I’ve already analyzed other questions, like, for example:
However the error still persists.
Note: I’ve already left the option enabled to allow less secure applications from my Gmail account. Also, using the Glassfish application manages to send the email. Apparently the problem is in Apache Tomcat.
Follows the code:
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
Session session1 = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("email", "senha");
}
});
/**
* Ativa Debug para sessão
*/
session1.setDebug(true);
try {
Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress("enviaremail")); //Remetente
String destinatario = (String) session.getAttribute("email");
Address[] toUser = InternetAddress //Destinatário(s)
.parse(destinatario);
message.setRecipients(Message.RecipientType.TO, toUser);
message.setSubject("Novo E-mail!"); //Assunto
message.setText("Olá. Você recebeu um novo e-mail.");
/**
* Método para enviar a mensagem
* criada
*/
Transport.send(message);
System.out.println("Feito!!!");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
I was able to solve the problem. It was in SSL!
– Victor
Glad you could help.
– Ederson Coelho