可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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