java - 在Spring Boot中使用YAML文件配置SMTP主机

标签 java spring-boot smtp

我正在尝试为我的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/

相关文章:

email - 如何使用 Rebol 的 SEND 功能将地址添加到 BCC 字段?

javascript - Protractor - 计算 xpath 中的元素并将其存储到 var

java - 如何知道用户是否已连接到互联网?

java - getForEntity 返回 null

java - Katharsis 结合 Spring Boot

java - 我在使用 Java Mail 发送的电子邮件中丢失了句号

java - JsonPath/ jackson : how to deserialize JSON array to a single Object ("[1,2,3]" -> Vector3d instance)?

java - 正则表达式替换 Java 文件中的所有字符串文字

java - Spring引导 Autowiring 类不会在常规类中实例化

asp.net - 无法获取IIS提取目录