Smtp
OPENSMTP is a good mail delivery component on the. Net platform, but there are some bugs affecting our use, I encountered in the use of the message subject length is large, the message appears garbled.
After examining the source code found that the original process is problematic: first, the theme is encoded by ASCII, followed by the use of QP encoding, but did not consider the difference between the subject and content.
When encoding in a topic, each line must be encoded separately, and the subject cannot be encoded all at once.
In contrast to Outlook Express, add a method to the MailEncoding class that specifically Base64 code for the subject of the message
public static string ConvertHeaderToBase64 (string s, String charset)
{
int linelength = 40; Processing 40 bytes per line
Encoding Encoding = encoding.getencoding (charset); Take the specified encoding
byte[] buffer = encoding. GetBytes (s); Convert to byte code
StringBuilder sb = new StringBuilder (); Save Final results
String linebase64;
int block = buffer. Length%linelength==0?buffer. Length/linelength:buffer. Length/linelength + 1;
for (int i=0; i< blocks; i++)
{
if (buffer). Length-i*linelength >=linelength)
Linebase64 = convert.tobase64string (buffer, i*linelength, linelength);
Else
Linebase64 = convert.tobase64string (buffer, i*linelength, buffer. Length-i*linelength);
Sb. Append ("=?");
Sb. Append (CharSet);
Sb. Append ("? B? ");
Sb. Append (LINEBASE64);
Sb. Append ("? =\r\n\t");
}
Sb. Remove (sb.) Length-3, 3); Delete last newline symbol
Return SB. ToString ();
}
Then, modify the handling of the message subject in the ToString method in the MailMessage class to invoke the custom method
Sb. Append ("Subject:" + MAILENCODER.CONVERTHEADERTOQP (cleansubject.tostring (), CharSet) + "\ r \ n");
Sb. Append ("Subject:" + mailencoder.convertheadertobase64 (cleansubject.tostring (), CharSet) + "\ r \ n");
Re-compiling can