gpt4 book ai didi

Spring 电子邮件 : Must issue a STARTTLS command first

转载 作者:行者123 更新时间:2023-12-02 02:45:50 25 4
gpt4 key购买 nike

我正在尝试使用 Spring Email 向自己发送一封简单的电子邮件,但我遇到了以下异常:

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p4sm7233776wrx.63 - gsmtp
; message exceptions (1) are:
Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p4sm7233776wrx.63 - gsmtp

通过谷歌搜索,我看到大多数人通过添加属性 spring.mail.properties.mail.smtp.starttls.enable=true 来解决这个问题,但我已经做到了,但还没有在我的案例中工作。

我的应用程序.properties:

spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myEmail@gmail.com
spring.mail.password=********
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true

我的代码:

@Service
@Slf4j
public class NotificationService {

@Autowired
private JavaMailSender javaMailSender;

public void sendNotification() {
SimpleMailMessage messaggio = new SimpleMailMessage();
messaggio.setTo("myEmail@gmail.com");
messaggio.setFrom("YourSpringFriend@gmail.com");
messaggio.setSubject("Test Spring Email");
messaggio.setText("Tadaaaa! Email da Spring!");
javaMailSender.send(messaggio);
}
}

我做错了什么?

提前感谢您的时间和经验

最佳答案

将此属性添加到您的 application.properties

spring.mail.properties.mail.smtp.starttls.enable=true

这个工作很好

关于 Spring 电子邮件 : Must issue a STARTTLS command first,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62821073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com