Hola estoy intentando enviar correos desde una aplicación java con javamail. El classpath tiene incluidos mail.jar y activation.jar. El caso es que no consigo enviarlos y no sé cual puede ser el error . El código es el siguiente y más abajo está el fallo que me da. Si podeis ayudarme, muchas gracias!!
Por cierto,si estoy utilizando el servidor de correo de yahoo, el login y el password son los de mi cuenta de correo,y ya está ....o no funciona así???????
void sendCompleteMessage(String addr) throws AddressException, MessagingException{
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.correo.yahoo.es");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth", "true");
Autentificador authen = new Autentificador();
Session session= Session.getDefaultInstance(props,authen);
session.setDebug(true);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("[email protected]"));
msg.setSubject("Report and Grapho of Interacion Analysis");
msg.setRecipient(Message.RecipientType.TO,new InternetAddress(addr));
msg.setSentDate(new Date());
String texto="";
try
{
FileReader fr = new FileReader("fSalida");
BufferedReader entrada = new BufferedReader(fr);
String s;
while((s = entrada.readLine()) != null)
{
texto = texto +s;
}
entrada.close();
}
catch(java.io.FileNotFoundException fnfex){
System.out.println("Archivo no encontrado: " + fnfex);
}
catch(java.io.IOException ioex){
ioex.printStackTrace();
}
msg.setContent(texto,"text/plain");
try{
Transport.send(msg);
}catch(MessagingException mex){
System.out.println(mex.toString());
}
}
public class Autentificador extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username = "username";
String password = "contrasegna";
return new PasswordAuthentication(username, password);
}
}
}
Y el error que da:
DEBUG: setDebug: JavaMail version 1.3.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.correo.yahoo.es", port 25, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: smtp.correo.yahoo.es, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1227)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SM TPTransport.java:322)
at javax.mail.Service.connect(Service.java:258)
at javax.mail.Service.connect(Service.java:137)
at javax.mail.Service.connect(Service.java:86)
at javax.mail.Transport.send0(Transport.java:150)
at javax.mail.Transport.send(Transport.java:80)
at mail.SendMail.sendCompleteMessage(SendMail.java:14 5)
at mail.SendMail.<init>(SendMail.java:78)
at IU.Ventana$33.actionPerformed(Ventana.java:733)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unk nown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mou seReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierar chy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)