我有設立的Outlook郵件到JavaMail的頭痛,我曾跟隨從here和說明here的Outlook電子郵件設置用來爲JavaMail API
Properties props = new Properties();
props.put("mail.smtp.user", d_email);
props.put("mail.smtp.host", "smtp-mail.outlook.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", "587");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "true");
try
{
Authenticator auth = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(d_email, d_password);
}
};
Session session = Session.getInstance(props, auth);
MimeMessage msg = new MimeMessage(session);
msg.setText("Hey, this is the testing email.");
msg.setSubject("Testing");
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
Transport.send(msg);
}catch (MessagingException mex) {
mex.printStackTrace();
}
而且我不斷收到錯誤:
javax.mail.MessagingException: Could not connect to SMTP host: smtp-mail.outlook.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
我已經搜索谷歌和stackoverflow,我想這是一個必須使用SSL而不是TLS,因爲outlook不接受TLS,否則連接將被遠程主機關閉,但我從互聯網上找到的解決方案並沒有工作出。我爲了成功發送測試郵件而錯過了什麼?
我是全新的郵件API,任何建議或幫助將不勝感激。謝謝。
編輯:我從微軟我註冊類似「[email protected]」
噢,我的上帝的工作,我終於解決它,當我登錄到我的outlook.live.com電子郵件,我看到一個消息來自outlook團隊的郵件,表示要繼續發送郵件,請登錄並驗證我的帳戶。幫助我們阻止發送垃圾郵件的自動程序。在我驗證了我的電子郵件之後,哦,我的上帝 –
有趣。從未見過。 –
無論如何感謝你們的努力和一切,一定要檢查回發送郵箱下次哈哈 –