2009-05-29 107 views
6

有誰知道的方式執行Gmail帳戶的每封電子郵件的批量轉儲和寫電子郵件到一個文件?下載電子郵件(備份)編程

我期待寫,將讓用戶備份有Gmail的(很可能是通過IMAP)的程序和備份到單個文件或爲PST(我知道PST可能會更難)

謝謝如果你能幫助

回答

5

前一段時間我寫了一篇博客文章完全相同的話題。詳細信息請參見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

的Gmail提供POPaccess。所以只需使用任何library即可使用POP進行通信,而且您是金牌。

編輯:我只注意到你提到IMAP;我建議您使用POP代替批量轉儲。對於你想要做的事情,IMAP太囉嗦了。

如果必須使用IMAP,這裏的a library你。

0

有編譯到Windows(使用py2exe)一個開放源碼的Python程序在 https://github.com/jay0lee/got-your-back/wiki

但Mac用戶將需要編譯它(我的天堂由於py2exe錯誤,我完全沒有想到)。

無論哪種方式,你還需要一種方法來在計劃自動執行程序。