2010-01-11 67 views
8

如何使用C#從我的郵件(例如gmail)下載電子郵件附件?如何在C#中保存電子郵件附件

+9

你希望我們爲你寫了完整的解決方案? – 2010-01-11 06:42:40

+0

此鏈接幫助我解決了同樣的問題,但是這有30天的試用期。 http://www.example-code.com/csharp/pop3_saveAttachments.asp快樂編碼 – Ravia 2010-01-11 06:43:17

+0

有關ans請參考:http://pop3saveattachment.blogspot.in/ – Raj 2013-01-22 08:19:02

回答

-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

相關問題