zoukankan      html  css  js  c++  java
  • 邮件收取客户端LumiSoft类库接收yahoo邮件的问题。

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    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  

    上面的代码是直接收取邮件,包括头字段和邮件正文。

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. new IMAP_t_Fetch_i_Rfc822()  

    注意,这句话是表示接收邮件的正文,而我经过测试,发现这段代码在接收yahoo邮箱的时候,邮件不能收取完全,因此在收取其他邮箱服务器的时候,可以采用上面的代码进行整体收件。

    因此可以改成下面的这段代码

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. if(ip=="apple.imap.mail.yahoo.com")  
    2.                                 {  
    3.                                     //开始循环取邮件数据                  
    4.                                     m_pImap.Fetch(  
    5.                                         true,  
    6.                                         IMAP_t_SeqSet.Parse("1:*"),  
    7.                                         new IMAP_t_Fetch_i[]{  
    8.                                             new IMAP_t_Fetch_i_Envelope(),  
    9.                                             new IMAP_t_Fetch_i_Flags(),  
    10.                                             new IMAP_t_Fetch_i_InternalDate(),  
    11.                                             new IMAP_t_Fetch_i_Rfc822Size(),  
    12.                                             new IMAP_t_Fetch_i_Uid(),  
    13.                                             //new IMAP_t_Fetch_i_Rfc822()  
    14.                                         },  
    15.                                         this.m_pImap_Fetch_MessageItems_UntaggedResponseyahoo  
    16.                                     );  
     


    这里实际上就没有采用直接收取正文的方式,实际上,这里只是收取了头字段。那么应该在其他地方继续写收件的代码。

    [csharp] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    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.             }  
    19.             this.Cursor = Cursors.Default;  
    20.         }  
    21.         //邮件读取回调函数  
    22.          private void m_pImap_Fetch_Message_UntaggedResponse(object sender,EventArgs<IMAP_r_u> e)  
    23.         {  
    24.             /* NOTE: All IMAP untagged responses may be raised from thread pool thread, 
    25.                 so all UI operations must use Invoke. 
    26.               
    27.                There may be other untagged responses than FETCH, because IMAP server 
    28.                may send any untagged response to any command. 
    29.             */  
    30.   
    31.             try{  
    32.                 if(e.Value is IMAP_r_u_Fetch){  
    33.                     IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;  
    34.                   
    35.                     this.BeginInvoke(new MethodInvoker(delegate(){  
    36.                         try{  
    37.                             fetchResp.Rfc822.Stream.Position = 0;  
    38.                             Mail_Message mime = Mail_Message.ParseFromStream(fetchResp.Rfc822.Stream);  
    39.                             fetchResp.Rfc822.Stream.Dispose();  
    40.   
    41.                             //m_pTabPageMail_MessagesToolbar.Items["save"].Enabled = true;  
    42.                             //m_pTabPageMail_MessagesToolbar.Items["delete"].Enabled = true;  
    43.                                       
    44.                             //m_pTabPageMail_MessageAttachments.Tag = mime;  
    45.                             foreach(MIME_Entity entity in mime.Attachments){  
    46.                                 //ListViewItem item = new ListViewItem();  
    47.                                 if(entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null){  
    48.                                     //item.Text = entity.ContentDisposition.Param_FileName;  
    49.                                 }  
    50.                                 else{  
    51.                                    // item.Text = "untitled";  
    52.                                 }  
    53.                                 //item.ImageIndex = 0;  
    54.                                // item.Tag = entity;  
    55.                                 //m_pTabPageMail_MessageAttachments.Items.Add(item);  
    56.                             }  
    57.   
    58.                             if(mime.BodyText != null){  
    59.                                // m_pTabPageMail_MessageText.Text = mime.BodyText;  
    60.                             }  
    61.                               
    62.                             try  
    63.                             {  
    64.                                 //写入eml  
    65.                                 str stringhandle=new str();  
    66.                                 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#";  
    67.                                 title=FilterSpecial(title);  
    68.                                 cstring mystring=new cstring();  
    69.                                 title=mystring.ENCODE(title);  
    70.                                 title+=".eml";    
    71.                                 //写入eml文件  
    72.                                 string filepro=Application.StartupPath+"\data\"+thisuser+"\"+global_user+"\"+folder+"\"+title;  
    73.                                 FileStream fs = new FileStream(filepro, FileMode.Create);//文件名和路径  
    74.                                 StreamWriter sw = new StreamWriter(fs);  
    75.                                 //开始写入  
    76.                                 sw.Write(mime);                           
    77.                                 //清空缓冲区  
    78.                                 sw.Flush();  
    79.                                 //关闭流  
    80.                                 sw.Close();  
    81.                                 fs.Close();  
    82.                             }  
    83.                             catch(Exception x)  
    84.                             {  
    85.                                   
    86.                             }  
    87.                               
    88.                         }  
    89.                         catch(Exception x){  
    90.                             MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);  
    91.                         }  
    92.                     }));  
    93.                 }  
    94.             }  
    95.             catch(Exception x){  
    96.                 MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);  
    97.             }  
    98.         }  


    也就是说,收取邮件头和邮件正文分开,这样就能收取包括yahoo在内的所有邮箱。代码是直接从我的工程文件里面拷出来的,作为参考,不能直接使用,但是保证是一定可以用的,更多问题可以联系我。

     

  • 相关阅读:
    netty内存泄漏
    Java并发编程:CountDownLatch、CyclicBarrier和Semaphore
    java 容器结构
    c3p0 一个数据库链接的例子
    eclipse java MemoryAnalyzer 查询内存泄漏 环境配置
    Java中数据库连接的一些方法资料汇总
    java io流
    MySQL的几个概念:主键,外键,索引,唯一索引
    mysql 一些常用指令
    mysql only_full_group_by问题
  • 原文地址:https://www.cnblogs.com/waw/p/6370880.html
Copyright © 2011-2022 走看看