很久没写JAVA程序了,原来用GMAIL发送邮件这么简单

本文介绍了如何在Spring Boot应用中配置并使用JavaMailSender发送邮件,特别是在使用GMAIL作为SMTP服务器时的注意事项,包括配置邮件服务信息、创建邮件发送服务类以及处理GMAIL的二次验证和APP Password设置。
摘要由CSDN通过智能技术生成

写完代码,配置了GMAIL,死活发布出去,碰到了错误535-5.7.8 Username and Password not accepted.

首先先写代码,然后配置GMAIL.

第一写代码:

当你需要在 Spring Boot 中实现邮件通知时,你可以使用 Spring 的 JavaMailSender 来发送电子邮件。首先,确保你的 Spring Boot 项目已经配置好了邮件发送功能。下面是一个示例代码,演示如何在 Spring Boot 中发送邮件通知:

首先,在 `application.properties` 或 `application.yml` 文件中配置邮件服务的信息,例如:

```properties
# SMTP邮件发送配置
spring.mail.host=your-smtp-server.com
spring.mail.port=587
spring.mail.username=your-email@example.com
spring.mail.password=your-email-password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
```

YML属性文件

spring:
  mail:
    host: your-smtp-server.com
    port: 587
    use

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值