I am trying to configure an SMTP host for my Spring boot application.
I have this code in my application-dev.yml
file:
mail:
host: smtp.gmail.com
port: 465
username: [email protected]
password: mypassword
However, when I am trying to send an email I get this exception:
Caused by: javax.mail.MessagingException: Could not connect to
SMTP host: smtp.gmail.com,
port: 465, response: -1
Also, I have generated this code with JHipster and I am not sure whether I should modify something else or this is enough to configure a SMTP host.
After changing the port to 587, I am getting this:
org.springframework.mail.MailSendException:
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue
a STARTTLS command first. jm6sm60863600wjb.27 - gsmtp
I made the following changes and now it works fine:
mail:
host: smtp.gmail.com
port: 587
username: [email protected]
password: mypassword
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
ssl.trust: smtp.gmail.com
I have used following YAML configuration for sending mail via Gmail
spring:
mail:
default-encoding: UTF-8
host: smtp.gmail.com
username: <Gmail username>
password: <Gmail password>
port: 587
properties:
mail:
smtp:
auth: true
starttls:
enable: true
protocol: smtp
test-connection: false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With