Reputation: 242
I'm using Gmail SMTP host to send mails with spring boot and JavaMail Sender:
my Mail properties:
spring.mail.host = smtp.gmail.com
spring.mail.username = [email protected]
spring.mail.password = XXX
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.starttls.enable = true
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
Getting error:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: smtp.9business.fr, port: 25, response: 421] with root cause
even if I'm using port 465 why is he pointing to port 25?
Upvotes: 4
Views: 36673
Reputation: 1
For Spring Boot. spring: mail: host: smtp.gmail.com port: 587 username: your-email password: 'your app-password' properties: mail: transport: protocol: smtp smtp: auth: true starttls: enable: true
Upvotes: 0
Reputation: 5233
disabled mail.smtp.starttls.required
to false
in your properties file.
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=false
Upvotes: 3
Reputation: 1
Try this
spring.mail.host = smtp.gmail.com
spring.mail.port = 587
spring.mail.username = xxxxxx
spring.mail.password = xxxxxx
spring.mail.properties.mail.smtp.starttls.enable = true
spring.mail.properties.mail.smtp.starttls.required = true
spring.mail.properties.mail.smtp.auth = true
Make sure google allow less secure app: https://myaccount.google.com/lesssecureapps turn it on
Upvotes: 0
Reputation: 242
Actually I found what going wrong, I should use both one of them is the port of my server and the other the one of gmail server :
spring.mail.properties.mail.smtp.socketFactory.port = 25
mail.smtp.port= 465
Upvotes: 3
Reputation: 9480
I'm not sure where you got those properties. The more common Spring Boot properties to configure can be found here:
http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
So you should probably be using spring.mail.port
. The properties available in the spring.mail
namespace are:
host
port
username
password
defaultEncoding (default: "UTF-8")
However, if you are creating your own JavaMailSender
, the property to set the SMTP port is mail.smtp.port
. I set up the JavaMailSender
as a bean like so:
@Value(value = "${mail.smtp.host}")
private String smtpHost;
@Value(value = "${mail.smtp.port}")
private String smtpPort;
@Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
Properties p = new Properties();
p.setProperty("mail.smtp.auth", "false");
p.setProperty("mail.smtp.host", smtpHost);
p.setProperty("mail.smtp.port", smtpPort);
sender.setJavaMailProperties(p);
return sender;
}
Upvotes: 3