Exchange Web服务API:获取邮件附件 [英] Exchange Web Services API : get mail attachments
本文介绍了Exchange Web服务API:获取邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是EWS 1.2 API来访问我们的Exchange服务器上的邮箱。 这只是工作正常,但有一件事我不能达到:收邮件的附件
I am using the EWS API 1.2 to access mailboxes on our Exchange Server. This just works fine but there is one thing I cannot achieve : get mail attachments.
林写了下面几行:
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<Item> 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<Attachment> e = item.Attachments.GetEnumerator();
}
Console.WriteLine(item.Subject);
}
else
Console.WriteLine("no items");
}
catch (Exception e) {
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
我得到的测试邮箱中的所有邮件,但的IEnumerator&LT;附件&GT; E = item.Attachments.GetEnumerator();
似乎并没有看附件
你有什么我错过了任何想法?
Have you got any idea of what I missed ?
多谢了。
推荐答案
我终于设法得到电子邮件附件。我修改了code如下
I finally managed to get email attachments. I modified my code as below
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<Item> 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();
}
}
这篇关于Exchange Web服务API:获取邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文