2010-01-11 44 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

相关问题