错误:阿里云服务器不能作为客户端通过STMP 25端口发送邮件。
解决:采用SSL协议发送邮件,端口号改成465。
配置文件
#邮箱配置
spring.mail.host=smtp.qiye.aliyun.com
spring.mail.username=邮箱账号
spring.mail.password=授权码
spring.mail.default-encoding=UTF-8
spring.mail.recevicer=接收者
#SSL证书Socket工厂
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
#使用SMTPS协议465端口
spring.mail.properties.mail.smtp.socketFactory.port=465
发送代码
@Autowired
private JavaMailSender mailSender;
public void send(String[] mailbox, String title, String content) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(username);
message.setTo(mailbox);
message.setSubject(title);
message.setText(content);
mailSender.send(message);
}

本文介绍了解决阿里云服务器无法通过STMP25端口发送邮件的问题,通过改用SSL协议和465端口实现邮件发送,并提供了Spring Boot配置示例和JavaMailSender发送代码。

1万+

被折叠的 条评论
为什么被折叠?



