简体   繁体   中英

javax.mail unable to send mail to hotmail

I'm trying to send mails using javax.mail from an hotmail account .
Until now I've tested my code also using gmail account and everything works fine, but with hotmail nothing works in particular, I receive a MailConnectException .
This is the code that I use in order to send the mail:

props.put("mail.starttls.enable", true);
props.put("mail.smtp.host", "smtp.live.com");
props.put("mail.smtp.port", "25");
props.put("mail.debug", true);
props.put("mail.smtp.auth", true);

As you can see I've created a PropertiesFactory in order to create a specific instance of the Properties object for each specific mail host that I use. In the code there is the factory for the HotmailProperties structure.

Starting a debugging session I've checked that useAuth option and isSSL are both equal to false.
What do I change in the properties configuration? Maybe there are some other errors in the code?

This is the debugging result of my program: http://ideone.com/SDu4JG

SOLVED I've solved my problem with the hotmail server. Looking to this page: http://windows.microsoft.com/en-us/windows/outlook/send-receive-from-app I've understood that hotmail, differently from the other mail servers like gmail and yahoo, considers the username as the complete email address. So when I do the login I always receive an error.

Finally it works. Thank you to all.

It's Working for me . Surely it will work for u :--

with port 587:--

        props.setProperty("mail.transport.protocol", "smtp");   
        props.setProperty("mail.smtp.host", "smtp.live.com");   
        props.put("mail.smtp.auth", "true");   
        props.put("mail.smtp.port", "587");   
        props.setProperty("mail.smtp.quitwait", "false");  
        props.put("mail.smtp.starttls.enable", "true");

    Session smtpSession = Session.getInstance(props1, authenticator);
        smtpSession.setDebug(true);

From your debug output:

MAIL FROM:<shadowtemplate@hotmail.com>
530 5.7.0 Must issue a STARTTLS command first
DEBUG SMTP: got response code 530, with response: 530 5.7.0 Must issue a STARTTLS command first

Status code 530 means that the client was not authenticated. (I googled "SMTP error status code 530" to get this)

Your message above indicates that TLS (transport layer security: encryption) is required

Apparently, Hotmail requires that you send mail over smtps and the default port is 587.

You named the properties mail.smtp s instead of mail.smtp

There is already a question which is solved, have a look: Java Mail over TLS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM