[Spring Mail prompts 504 error when sending email]

Spring Mail prompts 504 error when sending email

When working on a project, I used Spring Mail to send authentication emails. The local (Windows) function can be used normally, but when deployed to Alibaba Cloud, emails cannot be sent correctly. The specific reasons and solutions are as follows:
insert image description here

Spring Mail configuration

# MailProperties
spring.mail.host=smtp.163.com
[email protected] 
spring.mail.password=XXXXXXXXX
spring.mail.port=465
spring.mail.protocol=smtps
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

On the community registration function page, after the user enters the email address and clicks the registration button, the server should send a verification email to the user through spring mail. However, after deploying to the Alibaba Cloud server, the page waits for 60s (nginx sets the timeout time to 3 times and 30 seconds) and then prompts a 504 Gateway Timeout* error, indicating that the server did not process the request correctly.

Solution

Use the SSL protocol and adjust the port to port 465. Let’s talk about it in detail below.
The port is set to 465, and the ssl protocol type is set to smtp (the 465 port of the ingress and egress rules needs to be configured in Alibaba Cloud deployment. I have opened both the ingress and egress ports). According to this configuration, it can be called in Aliyun common

I didn’t configure the port to 465 at the beginning, enable ssl, and the protocol type is smtp. I can connect and send emails locally, but I can’t go to the Alibaba Cloud server.

Guess you like

Origin blog.csdn.net/qq_39236283/article/details/126471321