ASP.NET读取POP3邮件的操作__教程 |
|
日期:2007-5-20 1:19:10 人气:65 [大 中 小] |
|
|
|
//from the article "Retrieve Mail From a POP3 Server Using C#" at //www.codeproject.com by Agus Kurniawan //http://www.codeproject.com/csharp/popapp.asp string temp; try { temp = RdStrm.ReadLine(); was_pop_error(temp); return(temp); } catch(InvalidOperationException err) { return("Error in read_single_line_response(): " + err.ToString ()) ; }
} private string read_multi_line_response() { //read the response of the pop server. This code snipped "borrowed" //with some modifications... //from the article "Retrieve Mail From a POP3 Server Using C#" at //www.codeproject.com by Agus Kurniawan //http://www.codeproject.com/csharp/popapp.asp string temp=""; string szTemp;
try { szTemp = RdStrm.ReadLine(); was_pop_error(szTemp); if(!error) {
while(szTemp!=".") { temp += szTemp+CRLF; szTemp = RdStrm.ReadLine(); } } else { temp=szTemp; } return(temp); } catch(InvalidOperationException err) { return("Error in read_multi_line_response(): " + err.ToString ()); } } private void was_pop_error(string response) { //detect if the pop server that issued the response believes that //an error has occured.
if(response.StartsWith ("-")) { //if the first character of the response is "-" then the //pop server has encountered an error executing the last //command send by the client error=true; } else { //success error=false; } } #endregion #region POP commands public string DELE(int msg_number) { string temp;
if (state != connect_state.TRANSACTION ) { //DELE is only valid when the pop session is in the TRANSACTION STATE temp="Connection state not = TRANSACTION"; } else { issue_command("DELE " + msg_number.ToString ()); temp=read_single_line_response(); } return(temp); }
public string LIST() { string temp=""; if (state != connect_state.TRANSACTION ) { //the pop command LIST is only valid in the TRANSACTION state temp="Connection state not = TRANSACTION"; } else { issue_command ("LIST"); temp=read_multi_line_response(); } return(temp); }
public string LIST(int msg_number) { string temp="";
if (state != connect_state.TRANSACTION ) { //the pop command LIST is only valid in the TRANSACTION state temp="Connection state not = TRANSACTION"; } else { issue_command ("LIST " + msg_number.ToString ()); temp=read_single_line_response(); //when the message number is supplied, expect a single line response } return(temp);
}
public string NOOP() { string temp; if (state != connect_state.TRANSACTION ) { //the pop command NOOP is only valid in the TRANSACTION state temp="Connection state not = TRANSACTION"; |
|
出处:本站原创 作者:佚名 |
|
|