如何使用C#从我的邮件(例如gmail)下载电子邮件附件?如何在C#中保存电子邮件附件
8
A
回答
-3
以下代码取自Extract Attachments sample,它附带我们的Rebex Mail组件。 HOWTO: Download emails from a GMail account in C#博文中包含从POP3服务器下载的内容。
// 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);
}
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.
+0
我没有这样的方法和属性在'attachment'类,你使用过一些第三方库吗? – 2012-12-04 13:03:13
+1
我在哪里可以获得POP3Class库? – 2013-05-07 10:59:49
相关问题
- 1. 根据电子邮件主题保存电子邮件附件
- 2. 通过管道电子邮件保存电子邮件附件
- 3. 如何在php中保存电子邮件的附件?
- 4. 保存电子邮件附件
- 5. 如何将电子邮件附件另存为电子邮件?
- 6. 如何将电子邮件附件保存到文件
- 7. 保存电子邮件附件的附件
- 8. 如何使用Jython保存电子邮件图像附件
- 9. 如何从电子邮件CSV附件,并将其保存
- 10. 如何使用OpenPop保存电子邮件“消息”附件
- 11. 如何使用OpenPop保存电子邮件附件
- 12. 从Outlook中保存电子邮件附件文件
- 13. 从保存的电子邮件附件中读取kml文件
- 14. 如何在C#中下载电子邮件附件
- 15. C# - 将保存在数据库中的文件附加到电子邮件
- 16. 如何在PHP中将电子邮件附件保存到服务器?
- 17. 电子邮件中的附件以UTF-8编码保存
- 18. Powershell在过去几天内保存电子邮件附件
- 19. 如何将电子邮件附加到其他电子邮件?
- 20. 发送电子邮件附件C#
- 21. 保存电子邮件附件,以蟒蛇文件2.7
- 22. 保存文件并作为电子邮件附件发送
- 23. 如何导入电子邮件附件?
- 24. 如何阅读电子邮件附件
- 25. 如何将电子邮件的内容(电子邮件和附件)存储在SharePoint中的一个文件中?
- 26. 在PHP中的电子邮件附件?
- 27. 在电子邮件中附加文件
- 28. 在电子邮件中复制附件。
- 29. 如何发送电子邮件与附件中的附件
- 30. codeigniter电子邮件附件
你希望我们为你写了完整的解决方案? – 2010-01-11 06:42:40
此链接帮助我解决了同样的问题,但是这有30天的试用期。 http://www.example-code.com/csharp/pop3_saveAttachments.asp快乐编码 – Ravia 2010-01-11 06:43:17
有关ans请参考:http://pop3saveattachment.blogspot.in/ – Raj 2013-01-22 08:19:02