Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
781 views
in Technique[技术] by (71.8m points)

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

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 = [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

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...