2010-01-11 42 views
8

Làm cách nào để sử dụng C#, Tải xuống tệp đính kèm email từ thư của tôi (ví dụ gmail)?Cách lưu tệp đính kèm email trong C#

+9

Và bạn muốn chúng tôi viết giải pháp hoàn chỉnh cho bạn? –

+0

Liên kết này đã giúp tôi giải quyết cùng một vấn đề, nhưng điều này có 30 ngày dùng thử. http://www.example-code.com/csharp/pop3_saveAttachments.asp Chúc mừng mã hóa – Ravia

+0

Đối với ans vui lòng tham khảo: http://pop3saveattachment.blogspot.in/ – Raj

Trả lời

-3

Mã sau được lấy từ Extract Attachments sample đi kèm với thành phần Rebex Mail của chúng tôi. Tải xuống từ máy chủ POP3 được bao gồm trong blog bài đăng 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

Tôi không có các phương thức và thuộc tính như vậy trong lớp 'attachment' , bạn đã sử dụng một số libs của bên thứ 3 chưa? –

+1

Tôi có thể lấy thư viện POP3Class ở đâu? –

Các vấn đề liên quan