如何使用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. 如何使用OpenPop保存電子郵件附件
- 6. 從Outlook中保存電子郵件附件文件
- 7. 從保存的電子郵件附件中讀取kml文件
- 8. 如何在PHP中將電子郵件附件保存到服務器?
- 9. 如何將電子郵件附加到其他電子郵件?
- 10. 保存文件並作爲電子郵件附件發送
- 11. 如何閱讀電子郵件附件
- 12. 如何將電子郵件的內容(電子郵件和附件)存儲在SharePoint中的一個文件中?
- 13. 在PHP中的電子郵件附件?
- 14. 在電子郵件中附加文件
- 15. 電子郵件附件
- 16. PHP電子郵件附件
- 17. 電子郵件附件
- 18. 電子郵件附件
- 19. Powershell電子郵件附件
- 20. 電子郵件附件
- 21. 電子郵件附件?
- 22. 如何使用IMAP和PHP從電子郵件中保存圖像附件?
- 23. 如何將保存的文本文件作爲電子郵件附件發送
- 24. 保存來自Thunderbird的電子郵件正文及其附件
- 25. 宏將文件的保存版本附加到電子郵件
- 26. 將電子郵件附件保存到網絡位置
- 27. 將電子郵件附件保存到磁盤的產品
- 28. AWS SES - 收到的電子郵件保存附件S3
- 29. 使用雷鳥源保存電子郵件附件
- 30. 保存電子郵件附件(python3,pop3_ssl,gmail)
你希望我們爲你寫了完整的解決方案? – 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