如何在c#中下载电子邮件附件

时间:2012-06-13 15:29:23

标签: c# email attachment downloading

我可以在c#中使用免费库来下载电子邮件附件吗?是的,这个问题之前已经发布过,但之前的帖子已经过时了,其中引用的一些项目甚至不再维护了。我希望在过去的几年中出现一些新的东西。

此外,我更喜欢可以使用任何东西的东西,但是特定于Exchange Server的解决方案也可以。

1 个答案:

答案 0 :(得分:0)

您可以使用EA GetMail Component。我在这里举例说明使用IMAP协议从电子邮件获取附件

MailClient oClient = new MailClient("TryIt");

//ServerProtocol.Pop3 to ServerProtocol.Imap4 in MailServer constructor

MailServer oServer  = new MailServer(sServer, 
sUserName, sPassword, bSSLConnection, 
ServerAuthType.AuthLogin, ServerProtocol.Imap4);

//by default, the pop3 port is 110, imap4 port is 143, 
//the pop3 ssl port is 995, imap4 ssl port is 993
//you can also change the port like this
//oServer.Port = 110;

 oClient.Connect(oServer);
 MailInfo [] infos = oClient.GetMailInfos();
 int count = infos.Length;
 if(count!=0)
 {
   MailInfo info = infos[i];
   Mail oMail = oClient.GetMail(info);
   Attachment [] atts = oMail.Attachments;          
 }
相关问题