2010-01-11 100 views
8

¿Cómo puedo, usando C#, descargar un archivo adjunto de correo electrónico de mi correo (por ejemplo, gmail)?Cómo guardar adjuntos de correo electrónico en C#

+9

Y quieres que escribamos la solución completa para usted? –

+0

Este enlace me ayudó a resolver el mismo problema, pero esto tiene una prueba de 30 días. http://www.example-code.com/csharp/pop3_saveAttachments.asp Happy coding – Ravia

+0

Para ans, consulte: http://pop3saveattachment.blogspot.in/ – Raj

Respuesta

-3

El siguiente código está tomado de Extract Attachments sample que viene con nuestro componente Rebex Mail. La descarga desde un servidor POP3 está cubierta en el blog HOWTO: Download emails from a GMail account in C#.

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

No tengo tales métodos y propiedades en la clase 'attachment' , ¿usaste algunas librerías de terceros? –

+1

¿dónde puedo obtener la biblioteca POP3Class? –

Cuestiones relacionadas