【问题标题】:Download emails (backup) from gmail programmatically以编程方式从 gmail 下载电子邮件(备份)
【发布时间】:2010-10-29 22:15:47
【问题描述】:

有没有人知道一种方法可以批量转储 gmail 帐户的每封电子邮件并将这些电子邮件写入文件?

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

【问题讨论】:

    标签: c# email backup gmail imap


    【解决方案1】:

    您可以在 Unix 环境中使用 fetchmail 创建 mbox 文件。

    http://lifehacker.com/software/gmail/geek-to-live--back-up-gmail-with-fetchmail-235207.php

    【讨论】:

      【解决方案2】:

      Gmail 提供POPaccess。因此,只需使用任何library,它允许您使用 POP 进行通信,您就可以了。

      编辑:我刚刚注意到您提到了 IMAP;我建议您使用 POP 而不是批量转储。 IMAP 对于您想要做的事情来说太健谈了。

      如果您必须使用 IMAP,这里是 a library

      【讨论】:

      • 如果有人选择使用 POP,即使收件箱包含超过 1000 条消息,请务必检查代码是否有效。
      【解决方案3】:

      前段时间我写了一篇关于完全相同主题的博客文章。有关详细信息,请参阅HOWTO: Download emails from a GMail account in C#

      代码使用我们的Rebex Mail component:

      using Rebex.Mail;
      using Rebex.Net;
      ...
      // create the POP3 client
      Pop3 client = new Pop3();
      try
      {
      
         // Connect securely using explicit SSL. 
         // Use the third argument to specify additional SSL parameters. 
         Console.WriteLine("Connecting to the POP3 server...");
         client.Connect("pop.gmail.com", 995, null, Pop3Security.Implicit);
      
         // login and password
         client.Login(email, password);
      
         // get the number of messages
         Console.WriteLine("{0} messages found.", client.GetMessageCount());
      
         // -----------------
         // list messages
         // -----------------
      
         // list all messages
         ListPop3MessagesFast(client); // unique IDs and size only   
         //ListPop3MessagesFullHeaders(client); // full headers
      }
      finally
      {
         // leave the server alone
         client.Disconnect();      
      }
      
      
      public static void ListPop3MessagesFast(Pop3 client)
      {
         Console.WriteLine("Fetching message list...");
      
         // let's download only what we can get fast
         Pop3MessageCollection messages = 
            client.GetMessageList(Pop3ListFields.Fast);
      
         // display basic info about each message
         Console.WriteLine("UID | Sequence number | Length");
         foreach (Pop3MessageInfo messageInfo in messages)
         {
            // display header info
            Console.WriteLine
            (
               "{0} | {1} | {2} ",
               messageInfo.UniqueId,
               messageInfo.SequenceNumber,
               messageInfo.Length
            );
      
            // or download the whole message
            MailMessage mailMessage = client.GetMailMessage(messageInfo.SequenceNumber);
         }   
      }
      

      【讨论】:

        【解决方案4】:

        有一个开源 Python 程序编译到 Windows(使用 py2exe)在 https://github.com/jay0lee/got-your-back/wiki

        但 Mac 用户需要编译它(由于 py2exe 错误,我还没有完全弄清楚)。

        无论哪种方式,您还需要一种按计划自动执行程序的方法。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-09-25
          • 2010-11-22
          • 1970-01-01
          • 2014-03-18
          • 2011-10-21
          • 2014-08-25
          • 2011-01-31
          相关资源
          最近更新 更多