使用Exchange Web服务从Exchange下载附件 [英] Download attachment from Exchange using Exchange Web Services
问题描述
我尝试使用下面的代码来连接和使用C#和Exchange Web服务下载从电子邮件附件中的收件箱,但我得到一个'System.ArgumentOutOfRangeException'错误,我不能明白为什么。我用Google搜索的答案,但我不能找到一个或者我找到的答案是很老的版本EWS的。
我知道代码的其余部分通常的工作原理我可以访问与电子邮件等信息,只是没有访问附件。
藤有人告诉我我的方法错误?
在此先感谢,
詹姆斯
静态无效的主要(字串[] args)
{
ExchangeService服务=新ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials =新的NetworkCredential(MYLOGIN,MYPASSWORD,MYDOMAIN);
service.Url =新的URI(HTTPS://MYMAILSERVER/EWS/Exchange.asmx);
ServicePointManager.ServerCertificateValidationCallback = {委托返回true; };
FindItemsResults<项目> findResults = service.FindItems(WellKnownFolderName.Inbox,新ItemView控件(1000));
的foreach(在findResults.Items项项)
{
如果(item.HasAttachments&安培;&安培; item.Attachments [0]是FileAttachment的情况)
$ { b $ b FileAttachment的FileAttachment的= item.Attachments [0]作为FileAttachment的;
fileAttachment.Load(C:\\temp\\+ fileAttachment.Name);
}
}
}
}
解决,但新的问题
我已经改变了,现在的排序问题'的foreach(在findResults.Items项项)来的foreach(在findResults.Items EmailMessage项目),但现在我需要找出如何通过附件列举 - 任何想法吗
检查您的个人资料。如果你在光线模式下运行,附件不被使用的消息下载。
添加以下行
item.Load()//负载带附件
整个邮件
I am trying to use the following code to connect and download an attachment from email in an inbox using C# and Exchange Web Services but I am getting a 'System.ArgumentOutOfRangeException' error and I cant see why. I have googled for an answer but i cant find one or the answers I find are for very old versions of EWS.
I know that the rest of the code generally works as I can access other information relating to the email, just not access the attachment.
Cany anyone show me the error of my ways?
Thanks in advance,
James
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential("MYLOGIN", "MYPASSWORD", "MYDOMAIN");
service.Url = new Uri("https://MYMAILSERVER/EWS/Exchange.asmx");
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(1000));
foreach (Item item in findResults.Items)
{
if (item.HasAttachments && item.Attachments[0] is FileAttachment)
{
FileAttachment fileAttachment = item.Attachments[0] as FileAttachment;
fileAttachment.Load("C:\\temp\\" + fileAttachment.Name);
}
}
}
}
Solved but new problem
I have sorted the issue now by changing the 'foreach (Item item in findResults.Items)' to 'foreach (EmailMessage item in findResults.Items)' but now I need to find out how to enumerate through the attachments - any ideas anyone?
Check your profile. If you're running on light mode, attachments are not being downloaded with message.
add following line
item.Load() // loads the entire message with attachment
这篇关于使用Exchange Web服务从Exchange下载附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!