2010-01-11 14 views
8

Wie kann ich mit C# einen E-Mail-Anhang von meiner E-Mail herunterladen (z. B. Google Mail)?So speichern Sie E-Mail-Anhänge in C#

+9

Und Sie wollen, dass wir für Sie die komplette Lösung schreiben? –

+0

Dieser Link half mir, das gleiche Problem zu lösen, aber das hat 30 Tage Testversion. http://www.example-code.com/csharp/pop3_saveAttachments.asp Happy Coding – Ravia

+0

Für Ans bitte siehe: http://pop3saveattachment.blogspot.in/ – Raj

Antwort

-3

Der folgende Code stammt von Extract Attachments sample, der mit unserer Komponente Rebex Mail geliefert wird. Das Herunterladen von einem POP3-Server wird im HOWTO: Download emails from a GMail account in C# Blogpost behandelt.

// 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

Ich habe solche Methoden und Eigenschaften in der 'Anhang' Klasse , hast du einige 3rd-libs benutzt? –

+1

Wo kann ich die POP3Class-Bibliothek bekommen? –

Verwandte Themen