Recently, I have received some comments from some netizens about usingSmtpclientPass139,189, QQThe SMTP service in the mailbox fails to send emails. The returned error is"Authentication failedIn the same case, Outlook Express and Foxmail can be used to send messages normally.
To find out the cause, I tested it myself. The problem is true.
Based on this, we can determine that the problem should be the smtpclient itself. Besides,Authentication failed"Error, it should be in the authentication process. To thoroughly solve this problem, I used the method of capturing network packets to obtain the interaction information and packet capture tools when using Outlook Express and smtpclient to send emails, wireshark is a well-known Wireshark. I will not explain the use of this tool. If you are interested, visit the official website.
The Figure 2 below shows the packet capture process:
Next, let's compare and analyze why smtpclient fails.
For Figure 1 (outlook), we can see8Row, yesAuthentication successful, Indicates that the authentication is successful.
The3Line, I marked a red circle, which is the process of starting authentication. The following lists the authentication processes in both cases:
(1) Outlook Express
| Row number |
Sender |
Command |
| 3 |
Outlook Express |
AUTH LOGIN |
| 4 |
SMTP Server |
334 vxnlcm5hbwu6 (command meaning is user) |
| 5 |
Outlook Express |
The hidden part is the base64 encoding of the email account. |
| 6 |
SMTP Server |
334 ugfzc3dvcmq6 (the command indicates password) |
| 7 |
Outlook Express |
The hidden part is the base64 encoding of the email password. |
| 8 |
SMTP |
235 authentication successful authentication is successful. The content of the email is as follows: |
(2) smtpclient
| Row number |
Sender |
Command |
| 3 |
Smtpclient |
Auth login hidden part (content isBase64 encoding of the email account) |
| 4 |
SMTP Server |
334 vxnlcm5hbwu6 (command meaning is user) |
| 5 |
Smtpclient |
Hidden part, content isBase64 encoding of the email passwordBut what is actually needed here isBase64 encoding of the email account |
| 6 |
SMTP Server |
334 ugfzc3dvcmq6 (the command indicates password) |
| 7 |
Smtpclient |
Because the authentication process of smtpclient has ended, but the PASSWORD command of the SMTP server has been received, smtpclient considers the authentication failed. |
Through the comparison above, we can clearly find that while sending the auth login command, smtpclientEmail accountAlso sent together. Generally, the SMTP server can process the command correctly, so that the lines 3, 4, and 5 corresponding to Outlook Express are successfully completed, the command cannot be correctly identified, but the content after auth login is discarded, resulting inCommand MismatchThis is the key to the failure of smtpclient authentication.
. Net smtpclient authentication method, why not use Outlook Express, but adopts this seemingly concise method, the reason is, I don't know. (isn't it Microsoft developers trying to be lazy? )
There are many MVPs and other good guys in the garden, hoping to provide some help or ask Microsoft personnel this question.