spring中javaMail使用ssl的方法发送邮件,javaMail导入证书,忽略证书的方法

博客指出使用Spring Boot发邮件时出现报错,是Java使用SSL时证书信任问题。给出两种解决办法,一是将证书导入到JDK的信任证书中,介绍了Keytool的使用;二是忽略证书信任问题,添加相应配置。

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

使用配置

## 基础邮箱配置(每个环境可以覆盖配置)
# 发送者的邮箱地址
spring.mail.username=xxxx
# 发送者的邮箱密码
spring.mail.password=xxx
# 发送邮箱对应的SMTP地址
spring.mail.host=xxxx
spring.mail.port=465

发送邮件是出现报错

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

是java使用ssl时证书信任问题。

解决办法这里有两这种:

1)将证书导入到jdk的信任证书中:  JAVA 导入信任证书 (Keytool 的使用)

2)忽略证书信任问题: 添加相应配置:

## 基础邮箱配置(每个环境可以覆盖配置)
# 发送者的邮箱地址
spring.mail.username=xxxx
# 发送者的邮箱密码
spring.mail.password=xxxx
# 发送邮箱对应的SMTP地址
spring.mail.host=xxxx
spring.mail.port=465
spring.mail.default-encoding=UTF-8
# 这里填发送邮箱对应的SMTP地址 ,忽略证书,信任域名
spring.mail.properties.mail.smtp.ssl.trust=xxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值