Something about openpop/opensmtp/mail. net ......

Source: Internet
Author: User
Tags imap

Http://www.blogwind.com/Wuvist/21079.shtml

Thanks to hamidsforge, sheda0, unruledboy, and others for their contributions ...... Therefore, we can use the openpop/opensmtp open source. Net email components ...... And mail. Net after the two projects are merged.

Except these two (mail. net seems to have not been released.) I really don't know what else. net POP3 client can be used ,. net built-in SMTP function is too weak ......

I have been dealing with emails for a long time ...... Some experiences are not exclusive, so they are posted here:

1. Openpop may contain garbled characters when handling UTF-8-based Q-Encoded chinese letters, including the title and content

This should be a bug in the built-in quotedcoding class of mime parser. If you do not want to modify openpop'sCode, You can use the following:
If msg. contentcharset = "UTF-8" then
Subject = system. Text. encoding. utf8.getstring (system. Text. encoding. getencoding ("gb2312"). getbytes (msg. Subject ))
End if

The simple code can be done.

2. The date attribute of the message class in the mime parser of openpop deliberately ignores the influence of the time zone. You should call the datetimeinfo attribute to obtain the time zone information and then modify the time provided by the date, during the correction, I used code similar to the following: Public   Shared   Function fixtimezone () Function Fixtimezone ( Byval Timez As   String , Byref DT As Datetime)
Dim Lt As Timespan
Dim I As   Integer
If Timez. indexof ( " + " ) >   - 1   Then
Timez = Timez. substring (Timez. indexof ( " + " ) +   1 )
If   Char . Isdigit (Timez. Chars ( 2 )) Then
I =   2
Else
I =   3
End   If
Lt = Timespan. fromhours (convert. todouble (Timez. substring ( 0 , 2 )))
Lt = Lt. Add (timespan. fromminutes (convert. todouble (Timez. substring (I, 2 ))))
Lt = Lt. Subtract (system. timezone. currenttimezone. getutcoffset ( New Datetime ( 1999 , 1 , 1 )))
DT = DT. Subtract (LT)
Elseif Timez. indexof ( " - " ) >   - 1   Then
Timez = Timez. substring (Timez. indexof ( " - " ) +   1 )
If   Char . Isdigit (Timez. Chars ( 2 )) Then
I =   2
Else
I =   3
End   If
Lt = Timespan. fromhours (convert. todouble (Timez. substring ( 0 , 2 )))
Lt = Lt. Add (timespan. fromminutes (convert. todouble (Timez. substring (I, 2 ))))
Lt = Lt. Add (system. timezone. currenttimezone. getutcoffset ( New Datetime ( 1999 , 1 , 1 )))
DT = DT. Add (LT)
Elseif Timez. indexof ( " GMT " ) >   - 1   Then
DT = DT. Add (system. timezone. currenttimezone. getutcoffset ( New Datetime ( 1999 , 1 , 1 )))
End   If
End Function

3. Opensmtp does not set the file name encoding information when sending an attachment whose file name is Chinese, causing garbled characters.
Because opensmtp is used internally to add and send attachments, you must modify its code and re-compile ...... You need to modify the tomime function in attachment. cs. The content of the modified function is as follows: Public String tomime ()
{
Stringbuilder sb = New Stringbuilder ();
If (Contentid ! = Null )
{< br> Sb. append ( " content-ID: " + contentid + " >\ r \ n " );
}
String fname;
Fname = " \ " =? UTF - 8 ? Q ? " + Mailencoder. converttoqp (name, " UTF - 8 " ) + " ? = \ "" ;
Fname = Fname. Replace ( " \ R \ n " , "" );
Fname = Fname. Replace ( " = " , " = " );
SB. append ( " Content-Type: "   + Mimetype +   " ; \ R \ n " );
SB. append ( " Name = "   + Fname +   " \ R \ n " );
SB. append ( " Content-transfer-encoding: "   + Encoding +   " \ R \ n " );
SB. append ( " Content-Disposition: attachment; \ r \ n " );
SB. append ( " Filename = "   + Fname +   " \ R \ n " );

Filestream fin =   New Filestream (encodedfilepath, filemode. Open, fileaccess. Read );

Byte [] Bin;

While (Fin. Position ! = Fin. length)
{
Bin =   New   Byte [ 76 ];
Int Len = Fin. Read (bin, 0 , 76 );
SB. append (system. Text. encoding. utf8.getstring (bin, 0 , Len) + " \ R \ n " );
}

Fin. Close ();
Return SB. tostring ();
}

Openpop and opensmtp respectively use two email parser with the same purpose. They not only duplicate the invention wheel, but also impede the integration of the two. The emergence of mail. NET is quite appropriate ...... Well ...... In fact, I think the email parser itself should also be independent. net Control, which provides perfect space for the time zone issue of email sending and various encodings.

When it comes to perfection, even if mail. Net was born smoothly, it is not enough to be called the strongest ...... Because it does not support imap ...... You can Google IMAP. net. N companies rely on such components to make money, and they are very expensive ...... Even PHP/perl and so on have supported libraries for IMAP, in contrast,. netProgramIt seems so pitiful ...... However, no one provides the open-source. Net IMAP client.Rohit JoshiAlthough the C # IMAP client library provided is rough, I can use the openpop email parser to perform basic functions such as querying new messages in different directories.

I don't know. When will there be a truly strongest. Net open-source email component? If you already have one, please let me know ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.