You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已启用Exchange SMTP认证,Spring Boot应用仍无法发邮件的原因

解决方案

核心问题分析

异常信息明确指出租户级别的SMTP客户端认证被禁用,即便你已在单个邮箱层面启用SMTP认证,也会被租户级设置覆盖,导致认证失败。

步骤1:检查并启用租户级SMTP客户端认证

需通过Exchange Online PowerShell操作(需全局管理员权限):

  1. 连接Exchange Online PowerShell
  2. 查看当前租户SMTP认证状态:
    Get-TransportConfig | Select-Object SmtpClientAuthenticationDisabled
    
    若返回SmtpClientAuthenticationDisabled : True,说明租户级禁用了SMTP客户端认证。
  3. 启用租户级SMTP客户端认证:
    Set-TransportConfig -SmtpClientAuthenticationDisabled $false
    

步骤2:确认单个邮箱的SMTP认证状态

确保目标邮箱未被单独禁用SMTP认证:

  1. 检查目标邮箱设置:
    Get-CASMailbox tech@domain.com | Select-Object SmtpClientAuthenticationDisabled
    
  2. 若返回True,执行启用命令:
    Set-CASMailbox tech@domain.com -SmtpClientAuthenticationDisabled $false
    

步骤3:优化Spring Boot配置

你的基础配置无问题,可补充以下属性提升稳定性:

spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=tech@domain.com
spring.mail.password=xxxxxxxx # 若邮箱启用MFA,需使用应用密码而非普通登录密码
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000

额外注意事项

  • 若邮箱启用了多因素认证(MFA),必须使用应用密码替代普通登录密码,应用密码需在微软账户管理中心创建。
  • 租户级设置更改后,需等待15-30分钟生效,不要立即测试。

内容的提问来源于stack exchange,提问作者Harish Joshy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 17:45:09