boa tarde,
estou com problemas para enviar email com conexao segura TLS. Ele simplesmente não envia. segue o script, se alguém puder me ajudar…desde já muito obrigado.
package br.inpe.dsa.mail;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.MessagingException;
public class mail {
public boolean enviaEmail(String to, String from, String subject, String body) {
boolean status=false;
try {
Properties props = new Properties();
System.setProperty("javax.net.debug", "ssl,handshake");
props.put("mail.smtp.host", "meuservidor");
// props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.protocols", "SSLv3 TLSv1");
//Autenticação
Session sessao = Session.getDefaultInstance (props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "password");
}
});
MimeMessage message = new MimeMessage(sessao);
message.setFrom(new InternetAddress(from));
Address toAddress = new InternetAddress(to);
message.addRecipient(Message.RecipientType.TO, toAddress);
message.setSubject(subject);
message.setContent(body, "text/html");
Transport.send(message);
status = true;
} catch ( MessagingException msg) {
msg.printStackTrace();
status = false;
}
return status;
}
}