[英]JAVA Mail - Can't send email from corporate MS office network
以下是我從公司MS Office電子郵件ID發送電子郵件的代碼,但出現錯誤-javax.mail.AuthenticationFailedException:535 5.7.3身份驗證失敗。 我的用戶名和密碼正確。
final String user="abc@abc.com";
final String password = "1234";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
//props.put("mail.smtp.host", "smtp-mail.outlook.com");
props.put("mail.smtp.host", "outlook.office365.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(sendEmailAddress));
String text = "Test email";
message.setSubject("Test email");
message.setText(text);
Transport.send(message);
嘗試這個:
props.put("mail.smtp.host", "smtp.office365.com");
參考: Outlook郵件設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.