I am working with WebLogic
and I have a web service that returns a list of the database and also sends it by e-mail (gmail).
The problem is that, in my local environment everything works very well, the list returns the web service and I receive the mail in my inbox.
In production environment I receive the error:
"javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465; java.net.ConnectException: Connection timed out "..
I have tried with port 25 and similarly it only works in my local environment.
I've also tried "telnet smtp.gmail.com 25"
commands from my production server and received a response from the gmail server.
Any ideas? , What could make it impossible to connect to the SMTP server?
I attach my code:
final String correo_remitente=prop.getProperty("correo_remitente");
final String password=prop.getProperty("password");
final String correo_destinatario=prop.getProperty("correo_destinatario");
final String server=prop.getProperty("server");
// get the property value and print it out
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", server);
props.put("mail.smtp.port", "25");// tambien he puesto 465
props.put("mail.smtp.auth", "true");
Session session2 = Session.getInstance (props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(correo_remitente, password);
}
});
//Creamos el mensaje
Message msg = new MimeMessage(session2);
msg.setFrom(new InternetAddress(correo_remitente));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(correo_destinatario,false));
msg.setSubject("Mensaje de Prueba by Arthur");
msg.setText("Los siguientes artículos:\n"+x+" \n contienen errores, con fecha:"+ fecha.toString());
msg.setSentDate(new Date());
Transport.send(msg);
The variables are obtained from a config file and it is set for an outgoing mail from G-mail.
password=********
correo_remitente=*******
correo_destinatario=*******
server=smtp.gmail.com