C# を使用して、メール (gmail など) からメールの添付ファイルをダウンロードするにはどうすればよいですか?
23974 次
2 に答える
0
// Firstly you might want to use POP3Class which is mail support class.
POP3Class Pop3= new POP3Class();
pop3.DoConnect("your.mail.server",110,"username","password");
pop3.GetStat();
// and then you can use the below code for storing an attachment.
MailMessage mail = new MailMessage ();
Mail.Load (args[0]);
Console.WriteLine (
"Message contains {0} attachments.",
mail.Attachments.Count
);
// If message has no attachments, just exit
if (mail.Attachments.Count == 0)
return 0;
foreach (Attachment attachment in mail.Attachments)
{
// Save the file
Console.WriteLine ("Saving '{0}' ({1}).",
attachment.FileName, attachment.MediaType);
attachment.Save (attachment.FileName);
}
// Hope that helps.
于 2012-06-07T11:09:23.207 に答える
-3
次のコードは、 Rebex Mailコンポーネントに付属するExtract Attachments サンプルから取得したものです。POP3 サーバーからのダウンロードについては、HOWTO: C# ブログ投稿で GMail アカウントからメールをダウンロードするで説明されています。
// Load mail message from disk
MailMessage mail = new MailMessage ();
mail.Load (args[0]);
Console.WriteLine (
"Message contains {0} attachments.",
mail.Attachments.Count
);
// If message has no attachments, just exit
if (mail.Attachments.Count == 0)
return 0;
foreach (Attachment attachment in mail.Attachments)
{
// Save the file
Console.WriteLine ("Saving '{0}' ({1}).",
attachment.FileName, attachment.MediaType);
attachment.Save (attachment.FileName);
}
于 2010-07-08T18:44:35.130 に答える