Gmailアカウントのすべての電子メールの一括ダンプを実行して、電子メールをファイルに書き込む方法を知っている人はいますか?
ユーザーがgmailを(おそらくimap経由で)バックアップし、個々のファイルまたはpstとしてバックアップできるようにするプログラムを作成しようとしています(pstはおそらくはるかに難しいでしょう)
少し前に、まったく同じトピックについてブログ投稿を書きました。詳細については、「 HOWTO: C# で GMail アカウントからメールをダウンロードする」を参照してください。
コードはRebex Mail コンポーネントを使用します:
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);
}
}
Unix 環境から fetchmail を使用して、mbox ファイルを作成できます。
http://lifehacker.com/software/gmail/geek-to-live--back-up-gmail-with-fetchmail-235207.php
https://github.com/jay0lee/got-your-back/wikiには、(py2exe を使用して) Windows 用にコンパイルされたオープンソースの Python プログラムがあり ます。
ただし、Mac ユーザーはコンパイルする必要があります (py2exe エラーのため、完全にはわかりませんでした)。
いずれにせよ、プログラムをスケジュールに従って自動的に実行する方法も必要です。