邮件收取客户端LumiSoft类库接收yahoo邮件的问题。

时间:2023-03-09 18:40:28
邮件收取客户端LumiSoft类库接收yahoo邮件的问题。
  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. 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. );

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

  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. There may be other untagged responses than FETCH, because IMAP server
  27. may send any untagged response to any command.
  28. */
  29. try{
  30. if(e.Value is IMAP_r_u_Fetch){
  31. IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;
  32. this.BeginInvoke(new MethodInvoker(delegate(){
  33. try{
  34. fetchResp.Rfc822.Stream.Position = 0;
  35. Mail_Message mime = Mail_Message.ParseFromStream(fetchResp.Rfc822.Stream);
  36. fetchResp.Rfc822.Stream.Dispose();
  37. //m_pTabPageMail_MessagesToolbar.Items["save"].Enabled = true;
  38. //m_pTabPageMail_MessagesToolbar.Items["delete"].Enabled = true;
  39. //m_pTabPageMail_MessageAttachments.Tag = mime;
  40. foreach(MIME_Entity entity in mime.Attachments){
  41. //ListViewItem item = new ListViewItem();
  42. if(entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null){
  43. //item.Text = entity.ContentDisposition.Param_FileName;
  44. }
  45. else{
  46. // item.Text = "untitled";
  47. }
  48. //item.ImageIndex = 0;
  49. // item.Tag = entity;
  50. //m_pTabPageMail_MessageAttachments.Items.Add(item);
  51. }
  52. if(mime.BodyText != null){
  53. // m_pTabPageMail_MessageText.Text = mime.BodyText;
  54. }
  55. try
  56. {
  57. //写入eml
  58. str stringhandle=new str();
  59. 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#";
  60. title=FilterSpecial(title);
  61. cstring mystring=new cstring();
  62. title=mystring.ENCODE(title);
  63. title+=".eml";
  64. //写入eml文件
  65. string filepro=Application.StartupPath+"\\data\\"+thisuser+"\\"+global_user+"\\"+folder+"\\"+title;
  66. FileStream fs = new FileStream(filepro, FileMode.Create);//文件名和路径
  67. StreamWriter sw = new StreamWriter(fs);
  68. //开始写入
  69. sw.Write(mime);
  70. //清空缓冲区
  71. sw.Flush();
  72. //关闭流
  73. sw.Close();
  74. fs.Close();
  75. }
  76. catch(Exception x)
  77. {
  78. }
  79. }
  80. catch(Exception x){
  81. MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
  82. }
  83. }));
  84. }
  85. }
  86. catch(Exception x){
  87. MessageBox.Show("Error: " + x.ToString(),"Error:",MessageBoxButtons.OK,MessageBoxIcon.Error);
  88. }
  89. }
邮件收取客户端LumiSoft类库接收yahoo邮件的问题。

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