Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Hotmail connection with Java Mail

843834Feb 5 2010 — edited Feb 5 2010
Hello everybody,
ı have already gone through faq but could not overcome an issue in a code which tries to connect hotmail smtp server. Let me start with how I did it for smtp connection for yahoo server:


// user is yahoo mail user name (withouth @yahoo.com) , and pass is the password
// which connects to your mail.yahoo e-mail account
public static void tryConnecting(String user, String pass) throws MessagingException
{
// 1 - get a mail session
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", "smtp.mail.yahoo.com");
props.put("mail.smtps.port", 465);
props.put("mail.smtps.auth", "true");

Session session = Session.getDefaultInstance(props);
session.setDebug(true);

// 2 - establish the connection
Transport transport = session.getTransport();
transport.connect(user, pass);
//transport.close();
}

this code works perfectly and I can create and send mails through my yahoo mail account after creating the connetcion with this method. Now All I want this to configure it for my hotmail account so I tried as below:

// user is hotmail user name (this time with @hotmail.com) and pass is password for the account
public static void tryConnecting(String user, String pass) throws MessagingException
{

// 1 - get a mail session

// In one forum I have seen I should provide ssl for hotmail with this line
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

Properties props = new Properties();
props.put("mail.host","smtp.live.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true");
// this should be added as I figured out from faq of this forum
props.put("mail.smtp.starttls.enable","true");

Session session = Session.getDefaultInstance(props);
session.setDebug(true);

// 2 - establish the connection
Transport transport = session.getTransport();
transport.connect(user, pass);
//transport.close();
}

I can never get a connection with this code. I will be very very happy if someone is able to say what I am missing or what I should change in the code above.

Thanks.
Gorkem
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 5 2010
Added on Feb 5 2010
3 comments
413 views