如何使用 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 回答