i wrote a sample program to send a mail to my yahoo id
the program compiled perfectly when running i got this
error Could not connect to SMTP Host
What may be the mistake in this code
thanx n advance
bye
baskar
the sample progam and its error is below
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMail
{
public static void main (
String args[]) throws Exception
{
String host = "mail.yahoo.com";
String from = "baskar_rub@yahoo.com";
String to = "baskar_rub@yahoo.com";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props,null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
System.out.println(" setting subject and message ");
message.setSubject("hi ");
message.setText("how r u");
Transport.send(message);
System.out.println(" sent the message ");
System.out.println(" thanks ");
}
}
error on running
*** *** *** *** *** *** *** *** *** *** *** *** setting subject and message
Exception in
thread "main" javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: mai
l.yahoo.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at SendMail.main(SendMail.java:23)