天天看點

郵件收取用戶端LumiSoft類庫接收yahoo郵件的問題。

[csharp] ​​view plain​​ ​​copy​​

 ​​​​​

  1. //開始循環取郵件資料                  
  2.                                     m_pImap.Fetch(  
  3.                                                 false,  
  4.                                                 IMAP_t_SeqSet.Parse("1:*"),  
  5.                                                 new IMAP_t_Fetch_i[]{  
  6.                                                 new IMAP_t_Fetch_i_Envelope(),  
  7.                                                 new IMAP_t_Fetch_i_Flags(),  
  8.                                                 new IMAP_t_Fetch_i_InternalDate(),  
  9.                                                 new IMAP_t_Fetch_i_Rfc822Size(),  
  10.                                                 new IMAP_t_Fetch_i_Uid(),  
  11.                                                 new IMAP_t_Fetch_i_Rfc822()  
  12.                             },  
  13.                             this.m_pImap_Fetch_MessageItems_UntaggedResponse  

上面的代碼是直接收取郵件,包括頭字段和郵件正文。

 ​

​​

  1. new IMAP_t_Fetch_i_Rfc822()  

注意,這句話是表示接收郵件的正文,而我經過測試,發現這段代碼在接收yahoo郵箱的時候,郵件不能收取完全,是以在收取其他郵箱伺服器的時候,可以采用上面的代碼進行整體收件。

是以可以改成下面的這段代碼

  1. if(ip=="apple.imap.mail.yahoo.com")  
  2.                                 {  
  3.                                     //開始循環取郵件資料                  
  4.                                         true,  
  5.                                         IMAP_t_SeqSet.Parse("1:*"),  
  6.                                         new IMAP_t_Fetch_i[]{  
  7.                                             new IMAP_t_Fetch_i_Envelope(),  
  8.                                             new IMAP_t_Fetch_i_Flags(),  
  9.                                             new IMAP_t_Fetch_i_InternalDate(),  
  10.                                             new IMAP_t_Fetch_i_Rfc822Size(),  
  11.                                             new IMAP_t_Fetch_i_Uid(),  
  12.                                             //new IMAP_t_Fetch_i_Rfc822()  
  13.                                         },  
  14.                                         this.m_pImap_Fetch_MessageItems_UntaggedResponseyahoo  
  15.                                     );  

這裡實際上就沒有采用直接收取正文的方式,實際上,這裡隻是收取了頭字段。那麼應該在其他地方繼續寫收件的代碼。

  1. //調用讀取郵件函數  
  2.         private void LoadMessage(long uid)  
  3.         {       
  4.             this.Cursor = Cursors.WaitCursor;  
  5.             try{  
  6.                 // Start fetching.  
  7.                 m_pImap.Fetch(  
  8.                     true,  
  9.                     IMAP_t_SeqSet.Parse(uid.ToString()),  
  10.                     new IMAP_t_Fetch_i[]{  
  11.                         new IMAP_t_Fetch_i_Rfc822()  
  12.                     },  
  13.                     this.m_pImap_Fetch_Message_UntaggedResponse  
  14.                 );  
  15.             }  
  16.             catch(Exception x){  
  17.                 MessageBox.Show(this,"Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);  
  18.             this.Cursor = Cursors.Default;  
  19.         }  
  20.         //郵件讀取回調函數  
  21.          private void m_pImap_Fetch_Message_UntaggedResponse(object sender,EventArgs<IMAP_r_u> e)  
  22.         {  
  23.             /* NOTE: All IMAP untagged responses may be raised from thread pool thread, 
  24.                 so all UI operations must use Invoke. 
  25.                There may be other untagged responses than FETCH, because IMAP server 
  26.                may send any untagged response to any command. 
  27.             */  
  28.                 if(e.Value is IMAP_r_u_Fetch){  
  29.                     IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;  
  30.                     this.BeginInvoke(new MethodInvoker(delegate(){  
  31.                         try{  
  32.                             fetchResp.Rfc822.Stream.Position = 0;  
  33.                             Mail_Message mime = Mail_Message.ParseFromStream(fetchResp.Rfc822.Stream);  
  34.                             fetchResp.Rfc822.Stream.Dispose();  
  35.                             //m_pTabPageMail_MessagesToolbar.Items["save"].Enabled = true;  
  36.                             //m_pTabPageMail_MessagesToolbar.Items["delete"].Enabled = true;  
  37.                             //m_pTabPageMail_MessageAttachments.Tag = mime;  
  38.                             foreach(MIME_Entity entity in mime.Attachments){  
  39.                                 //ListViewItem item = new ListViewItem();  
  40.                                 if(entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null){  
  41.                                     //item.Text = entity.ContentDisposition.Param_FileName;  
  42.                                 }  
  43.                                 else{  
  44.                                    // item.Text = "untitled";  
  45.                                 //item.ImageIndex = 0;  
  46.                                // item.Tag = entity;  
  47.                                 //m_pTabPageMail_MessageAttachments.Items.Add(item);  
  48.                             }  
  49.                             if(mime.BodyText != null){  
  50.                                // m_pTabPageMail_MessageText.Text = mime.BodyText;  
  51.                             try  
  52.                             {  
  53.                                 //寫入eml  
  54.                                 str stringhandle=new str();  
  55.                                 string title=mime.From.ToString()+"#"+stringhandle.strlen(mime.Subject.ToString(),20)+"#"+mime.Date.ToString("yyyy年MM月dd日 HH時mm分")+"#"+(mime.BodyText.Length / (decimal)1000).ToString("f2") + " kb#";  
  56.                                 title=FilterSpecial(title);  
  57.                                 cstring mystring=new cstring();  
  58.                                 title=mystring.ENCODE(title);  
  59.                                 title+=".eml";    
  60.                                 //寫入eml檔案  
  61.                                 string filepro=Application.StartupPath+"\\data\\"+thisuser+"\\"+global_user+"\\"+folder+"\\"+title;  
  62.                                 FileStream fs = new FileStream(filepro, FileMode.Create);//檔案名和路徑  
  63.                                 StreamWriter sw = new StreamWriter(fs);  
  64.                                 //開始寫入  
  65.                                 sw.Write(mime);                           
  66.                                 //清空緩沖區  
  67.                                 sw.Flush();  
  68.                                 //關閉流  
  69.                                 sw.Close();  
  70.                                 fs.Close();  
  71.                             catch(Exception x)  
  72.                         }  
  73.                         catch(Exception x){  
  74.                             MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);  
  75.                     }));  
  76.                 }  
  77.                 MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);