我正在开发一个使用hotmail账户发送电子邮件的Web应用程序。这是我的代码:
我非常确定账户凭证是正确的,但身份验证失败了。此外,我必须说,当我尝试这样做时,我收到了微软的电子邮件,称有人试图欺诈性地启动会话,但当我在本地执行代码时,我没有收到这封电子邮件。 我查看了账户信息页面和安全与隐私部分,发现我的最近活动中出现了关于发送电子邮件的挑战性安全问题。在此信息中,设备和平台未知,IP地址是我的主机IP。 有什么办法解决这个问题吗?
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;}
当我在本地使用这段代码时一切正常,但是当我将我的应用程序部署到托管服务器上时,出现了以下跟踪:
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
我非常确定账户凭证是正确的,但身份验证失败了。此外,我必须说,当我尝试这样做时,我收到了微软的电子邮件,称有人试图欺诈性地启动会话,但当我在本地执行代码时,我没有收到这封电子邮件。 我查看了账户信息页面和安全与隐私部分,发现我的最近活动中出现了关于发送电子邮件的挑战性安全问题。在此信息中,设备和平台未知,IP地址是我的主机IP。 有什么办法解决这个问题吗?