Well i have many tried to send email .But the exception arise can any body tell where i am wrong.
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MailExample {
public static void main (
String args[]) throws Exception {
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host","mail.yahoo.com");
// Get session
Session session = Session.getDefaultInstance(props, null);
// Define message
MimeMessage message = new MimeMessage(session);
// Set the from address
message.setFrom(new InternetAddress
"
[email protected]"));
// Set the to address
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("
[email protected]"));
// Set the subject
message.setSubject("Hello JavaMail");
// Set the content
message.setText("Welcome to JavaMail i got it");
// Send message
Transport.send(message);
}
}
Exception in
thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.MessagingException: Could not connect to SMTP host: mail.yaho
o.com, port: 25;
nested exception is:
java.net.NoRouteToHostException: Operation timed out: no further informa
tion
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at MailExample.main(MailExample.java:35)
Thanks
Jawwad Ahmed