Friends who have used the C # built-in SMTP class probably know that when using it to send emails, sometimes there are always inexplicable errors, sometimes it can be sent successfully, sometimes it is said that the user account verification fails, even if you have set the account verification information, the problem persists, especially when you use a QQ mailbox (as if SMTP is normal for 163). Basically, it is impossible to use an SMTP object to send emails, later, I found some materials and said that the QQ protocol seems to be ESMTP, that is, the enhanced SMTP protocol. I don't know if it is. There are many people who use QQ emails anyway, the issue of sending is more prominent.
In particular, my software "QQ number collection and email sending system" has been using SMTP class to handle mail sending. The problem that the customer reported that QQ mail was not successfully sent is particularly prominent, however, I didn't know how to deal with this problem at the time. I found a lot of materials at night, and the problem remained a headache. Let's take a look at the interface of my mail sending software first.
This software has now implemented the ESMTP protocol Batch Sending function. The test showed that 163 also supports ESMTP protocol. It is estimated that most SMTP providers support this interface, for them, this is a safer and less spam protocol, as if there are some "real-name" rules that we call everyday. Unlike SMTP mail, ESMTP sends TCP/IP commands to the server in a stream mode to obtain the interactive response mode. For example, to connect to the SMTP server, first, use the following code to connect. // Connect to the network
Try
{
Tc = new TcpClient (mailserver, mailserverport );
}
Catch (Exception e)
{
Errmsg = e. ToString ();
Return false;
}
Ns = tc. GetStream ();
/// <Summary>
/// Receive the SMTP server response
/// </Summary>
Protected string RecvResponse ()
{
Int StreamSize;
String ReturnValue = "false ";
Byte [] ReadBuffer = new byte [4096];
Try
{
StreamSize = ns. Read (ReadBuffer, 0, ReadBuffer. Length );
}
Catch
{
Errmsg = "network connection error ";
Return ReturnValue;
}
If (StreamSize = 0)
{
Return ReturnValue;
}
Else
{
& Nb