我正在尝试为我的Spring Boot应用程序配置SMTP主机。
我的application-dev.yml
文件中有以下代码:
mail:
host: smtp.gmail.com
port: 465
username: myemail@gmail.com
password: mypassword
但是,当我尝试发送电子邮件时,出现此异常:
Caused by: javax.mail.MessagingException: Could not connect to
SMTP host: smtp.gmail.com,
port: 465, response: -1
另外,我已经使用JHipster生成了此代码,并且不确定是否应该修改其他内容还是足以配置SMTP主机。
将端口更改为587后,我得到以下信息:
org.springframework.mail.MailSendException:
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue
a STARTTLS command first. jm6sm60863600wjb.27 - gsmtp
最佳答案
我进行了以下更改,现在可以正常使用:
mail:
host: smtp.gmail.com
port: 587
username: mymail@gmail.com
password: mypassword
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.gmail.com
关于java - 在Spring Boot中使用YAML文件配置SMTP主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41351540/