java - AuthenticationFailedException in sending email from java code
问题描述
I am trying to write a small java program that can send email from my corporate outlook account. I am planning to run this java program on my office machine only. Below is my program:
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.port", "587");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(my_email_id, my_password);
}
});
MimeMessage mime = new MimeMessage(session);
try {
mime.setSender(new InternetAddress(emailid));
mime.setRecipient(Message.RecipientType.TO, new InternetAddress(emailid));
mime.setSubject("Test");
mime.setText("Testing");
Transport.send(mime);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am getting below error :
javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [BM1PR01CA0166.INDPRD01.PROD.OUTLOOK.COM]
I have tried removing the socketFactory properties as well, but no luck. Can anyone help me out with this one? I am guessing it might have something to do with proxy or any other security on my office machine, but I am not able to figure out what it is.
解决方案
推荐阅读
- reactjs - setstate 中的箭头函数使用
- node.js - 如何在 aws ec2 中从域调用节点 js API
- php - Paypal 支付网关无法使用 curl 请求
- reactjs - 为什么 React - Create-React-Applications 不允许符号链接?
- regex - 正则表达式使用字符拆分并用不同的字符串替换第一部分
- spring-boot - Kafka 消费者在偏移提交后无法读取所有消息(错误=OFFSET_OUT_OF_RANGE
- javascript - 当我使用 getElementsbyClassName 时,无法使用 Vanilla JS 增加 div 的宽度
- python - 调用函数会导致所需的位置参数错误
- python - 买卖股票的最佳时机——Python 中的另一种方法
- java - 基于 ByteArrayInputStream 在 Java 中创建 DataFrame