Csharp/C#教程:Exchange Web服务API:获取邮件附件分享


Exchange Web服务API:获取邮件附件

我使用EWS API 1.2访问Exchange Server上的邮箱。 这只是工作正常,但有一件事我无法实现:获取邮件附件。

我写了以下几行:

class Program { public static void Main(string[] args) { try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); service.Credentials = new WebCredentials("login","password"); service.AutodiscoverUrl("mail@domaine.fr"); ItemView view = new ItemView(10); FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10)); if (findResults != null && findResults.Items != null && findResults.Items.Count > 0) foreach (Item item in findResults.Items) { if (item.Attachments != null) { IEnumerator e = item.Attachments.GetEnumerator(); } Console.WriteLine(item.Subject); } else Console.WriteLine("no items"); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); } } 

我收到了测试邮箱中的所有邮件,但IEnumerator e = item.Attachments.GetEnumerator(); 似乎没有“看到”附件。

你知道我错过了什么吗?

非常感谢。

我终于设法获得了电子邮件附件。 我修改了我的代码如下

上述就是C#学习教程:Exchange Web服务API:获取邮件附件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 class Program { public static void Main(string[] args) { try { ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); service.Credentials = new WebCredentials("login","pwd"); service.AutodiscoverUrl("mail@domaine.com"); ItemView view = new ItemView(10); FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10)); if (findResults != null && findResults.Items != null && findResults.Items.Count > 0) foreach (Item item in findResults.Items) { EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments)); foreach (Attachment attachment in message.Attachments) { if (attachment is FileAttachment) { FileAttachment fileAttachment = attachment as FileAttachment; fileAttachment.Load(); Console.WriteLine("Attachment name: " + fileAttachment.Name); } } Console.WriteLine(item.Subject); } else Console.WriteLine("no items"); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/991676.html

(0)
上一篇 2021年12月24日
下一篇 2021年12月24日

精彩推荐