I'm doing a web application for send e-mails with a hotmail account. This is my code:
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "smtp.live.com");
props.put("mail.smtp.auth", true);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.user", "mail@hotmail.com");
props.put("mail.smtp.pwd", pass);
props.put("mail.debug", true);
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
try {
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("othermail@otherserver.com"));
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress("mail@hotmail.com"));
mimeMessage.setSubject(subject);
mimeMessage.setContent(message, "text/html; charset=UTF-8");
mimeMessage.setSentDate(new Date());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.connect("smtp.live.com", "mail@hotmail.com", pass);
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
} catch (MessagingException e) {
ret = false;}
When I use this code in local everything works but when I deploy my application on my hosting server appears the follow trace:
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.live.com", port 587, isSSL false
220 BLU436-SMTP170.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at Thu, 14 Jan 2016 00:04:21 -0800
DEBUG SMTP: connected to host "smtp.live.com", port: 587
EHLO sbi02.namesservers.net
250-BLU436-SMTP170.smtp.hotmail.com Hello [37.187.179.160]
250-TURN
250-SIZE 41943040
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-TLS
250-STARTTLS
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41943040"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "TLS", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "OK", arg ""
STARTTLS
220 2.0.0 SMTP server ready
EHLO sbi02.namesservers.net
250-BLU436-SMTP170.smtp.hotmail.com Hello [37.187.179.160]
250-TURN
250-SIZE 41943040
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-AUTH LOGIN PLAIN XOAUTH2
250 OK
DEBUG SMTP: Found extension "TURN", arg ""
DEBUG SMTP: Found extension "SIZE", arg "41943040"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8bitmime", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2"
DEBUG SMTP: Found extension "OK", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
535 5.0.0 Authentication Failed
I am quite sure that the account credentials are correct but the authentication fails. Also I have to say that when I try to do this I receive an e-mail of microsoft says there has been a fraudulent attempt to start session but when I execute the code in local I don't receive this e-mail. I looked at the page account information and the securty & Privacity section, see my recent activity appears challenge security about this try of send e-mail. In this information the device and platform is unknow and the ip is the of my hosting. There any way to do this?