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);

}

}

}

[4735 byte] By [andres_265a] at [2007-10-2 3:28:39]
# 1

Hello

I'm was the same problem and fix it in two steps:

- Change to newer version of JavaMail (I try with 1.4ea).

- Change the protocol to send mail, in this case smtps, because the problem is that you try to send mail to a secure port of smtp.

e.g. in your code:

props.put("mail.smtps.host", host);

props.put("mail.transport.protocol", "smtps");

props.put("mail.smtps.auth", "true");

// Get authenticator

Authenticator auth = new Autenticador("userSmtp", "passSmtp");

// Get session

Session session = Session.getDefaultInstance(props, auth);

session.setProtocolForAddress("rfc822", "smtps");

Good Luck!!!

OcELLa at 2007-7-15 22:38:18 > top of Java-index,Java Essentials,Java Programming...