Help with encrypted mail!
Hi, I'm trying to build a tool to send mail but when I run the program a "E-mail Scanner window" pops up with this message:
"An encrypted email connection has been detected" and I can't send the mail. Once I've closed this window appears this message:
Exception in thread "main" javax.mail.MessagingException: 454 TLS not available due to temporary reason
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1308)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1168)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:330)
at javax.mail.Service.connect(Service.java:236)
at javax.mail.Service.connect(Service.java:137)
at MailExample.main(MailExample.java:54)
Java Result: 1
Can anybody help me? Here is the code I'm using:
import java.util.Properties;
import javax.mail.*;
import javax.mail.Session;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
publicclass MailExample{
privatestatic String host ="smtp.gmail.com";
privatestatic String user ="aaa";
privatestatic String password ="XXX";
privatestatic String from ="aaa@gmail.com";
privatestatic String to ="bbb@gmail.com";
publicstaticvoid main (String args[])throws Exception{
// Get system properties
Properties props =new Properties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth","true");
Authenticator auth =new Autenticador();
// Get session
Session session = Session.getDefaultInstance(props, auth);
// Define message
MimeMessage message =new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress(from));
// Set the to address
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail");
// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, user, password);
transport.send(message);
transport.close();
}
privatestaticclass Autenticadorextends javax.mail.Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
String usuario = user;
String clave = password;
returnnew PasswordAuthentication(usuario, clave);
}
}
}

