c# – 以编程方式从gmail下载电子邮件(备份)

前端之家收集整理的这篇文章主要介绍了c# – 以编程方式从gmail下载电子邮件(备份)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有人知道如何执行gmail帐户的每封电子邮件的批量转储并将电子邮件写入文件

我正在寻找一个程序,让用户备份gmail(可能通过imap)并将其备份到单个文件或作为pst(我知道pst可能会更难)

谢谢,如果你能提供帮助

解决方法

前段时间我写了一篇关于完全相同主题的博文.有关详情,请参见 HOWTO: Download emails from a GMail account in C#.

代码使用我们的Rebex Mail component

  1. using Rebex.Mail;
  2. using Rebex.Net;
  3. ...
  4. // create the POP3 client
  5. Pop3 client = new Pop3();
  6. try
  7. {
  8.  
  9. // Connect securely using explicit SSL.
  10. // Use the third argument to specify additional SSL parameters.
  11. Console.WriteLine("Connecting to the POP3 server...");
  12. client.Connect("pop.gmail.com",995,null,Pop3Security.Implicit);
  13.  
  14. // login and password
  15. client.Login(email,password);
  16.  
  17. // get the number of messages
  18. Console.WriteLine("{0} messages found.",client.GetMessageCount());
  19.  
  20. // -----------------
  21. // list messages
  22. // -----------------
  23.  
  24. // list all messages
  25. ListPop3MessagesFast(client); // unique IDs and size only
  26. //ListPop3MessagesFullHeaders(client); // full headers
  27. }
  28. finally
  29. {
  30. // leave the server alone
  31. client.Disconnect();
  32. }
  33.  
  34.  
  35. public static void ListPop3MessagesFast(Pop3 client)
  36. {
  37. Console.WriteLine("Fetching message list...");
  38.  
  39. // let's download only what we can get fast
  40. Pop3MessageCollection messages =
  41. client.GetMessageList(Pop3ListFields.Fast);
  42.  
  43. // display basic info about each message
  44. Console.WriteLine("UID | Sequence number | Length");
  45. foreach (Pop3MessageInfo messageInfo in messages)
  46. {
  47. // display header info
  48. Console.WriteLine
  49. (
  50. "{0} | {1} | {2} ",messageInfo.UniqueId,messageInfo.SequenceNumber,messageInfo.Length
  51. );
  52.  
  53. // or download the whole message
  54. MailMessage mailMessage = client.GetMailMessage(messageInfo.SequenceNumber);
  55. }
  56. }

猜你在找的C#相关文章