office365 java,使用Office365发送Javamail

本文提供了解决使用Java javax.mail 1.4.4通过Office365发送邮件时SMTP设置问题的方法。关键步骤包括启用TLS,设置SMTP端口为587,主机为m.outlook.com,并进行身份验证。示例代码中展示了如何实例化Properties和Session对象,以及如何使用Authenticator进行授权。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm having trouble configuring the SMTP settings for sending mail using javax.mail (1.4.4) through Office365, so I thought I'd post the properties here for others.

解决方案

Use Office365 smtp details as below:

private static Properties props;

private static Session session;

static {

props = new Properties();

props.put("mail.smtp.starttls.enable", "true");

props.put("mail.smtp.port", "587");

props.put("mail.smtp.host", "m.outlook.com");

props.put("mail.smtp.auth", "true");

session = Session.getInstance(props, new Authenticator() {

@Override

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication("office365 email address",

"office365 password");

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值