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

Google关闭低安全应用选项后,SpringBoot中JavaMailSender如何配置?

配置SpringBoot Java Mail Sender使用谷歌应用专用密码

前置准备

  • 给你的谷歌邮箱账户开启两步验证
  • 生成对应应用的应用专用密码(生成时选择「邮件」类型,适配Java Mail Sender场景)

修改SpringBoot配置文件

将原来配置里的邮箱登录密码替换为刚生成的应用专用密码即可,以下是两种常见配置文件的示例:

application.properties 配置

spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=your-gmail-account@gmail.com
# 替换为你的应用专用密码
spring.mail.password=your-app-specific-password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

application.yml 配置

spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username: your-gmail-account@gmail.com
    password: your-app-specific-password
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true

注意事项

  • 应用专用密码是16位字符串,复制时无需保留空格,直接完整粘贴即可
  • 未开启两步验证的谷歌账号无法生成应用专用密码,请确保前置步骤完成
  • 若仍出现访问问题,可检查谷歌账户设置中SMTP服务是否处于启用状态(默认已开启)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 21:27:12