c# - 如何在C#中保存电子邮件附件

标签 c# .net email attachment pop3

<分区>

如何使用 C# 从我的邮件(例如 gmail)中下载电子邮件附件?

最佳答案

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

关于c# - 如何在C#中保存电子邮件附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2040321/

相关文章:

c# - 如何测试我的套接字异常处理代码?

javascript - 如何覆盖电子邮件输入验证器消息?

c# - Visual Studio 在构建期间编译 WPF 应用程序两次

c# - Entity Framework - 一对多关系的问题

c# - SignalR 拒绝连接

c# - 在 C# 中声明泛型静态方法

c# - 在泛型接口(interface)中实现可空类型

c# - C#.net循环线程堆栈溢出

mysql - 通过 mysql bash 发送电子邮件

css - 造型邮件黑猩猩形式