Spring Boot - Could not connect to SMTP host: smtp.gmail.com, port: 25, response: 421

匿名 (未验证) 提交于 2019-12-03 02:01:02

问题:

I'm using gmail smtp host t send mails with spring boot and JavaMail Sender :

my Mail properties :

 spring.mail.host = smtp.gmail.com  spring.mail.username = XXX@gmail.com  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 

Geting 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 ?

回答1:

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; } 


回答2:

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



回答3:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!