Solve the error when sending emails using Hutool: MailConnectException: Couldn‘t connect to host, port: smtp.qq.com, 456; timeout -1

Problem Description

Today I used Hutool to send text messages, using qq mailbox and smtp protocol.

Therefore, after the parameter configuration is completed, the error timeout is reported when calling as follows:

Insert image description here

Exception in thread “main” cn.hutool.extra.mail.MailException: MailConnectException: Couldn’t connect to host, port: smtp.qq.com, 456; timeout -1

analyse problem

Obviously, this is a connection failure timeout issue.

I found the port 456 of the SMTP protocol on the Internet, but now I can’t connect. Some people on the Internet said that SSL is not turned on. Then I added it and tried it, but it still didn’t work. It still times out.

Insert image description here

At this time, I suspected that the port was wrong. Or some parameters are missing.

Solve the problem

At this time, I searched online and found this sentence:

The QQ mailbox SMTP server address is "smtp.qq.com"
Note:
1. The SMTP server requires authentication.
2. If the SSL encryption method of SMTP is set, the SMTP server port is 465 or 587.

The port was mentioned, and then I changed the port to 587. It worked this time

Insert image description here

Receive text message

Insert image description here

But if you add the SSL protocol, it won't work. I don't know why.

Insert image description here

Summarize

I really don’t understand some of the knowledge involved. Corrections are welcome and I hope it can help everyone close the gap.

Guess you like

Origin blog.csdn.net/weixin_46713508/article/details/134266781