c# – EWS只读取我的收件箱
发布时间:2020-12-16 02:00:32 所属栏目:百科 来源:网络整理
导读:参见英文答案 Wrong mailbox items being retrieved using Exchange Web Services managed API in C#????????????????????????????????????2个 我正在尝试阅读特定的电子邮件帐户,以查找包含未读附件的项目,并在主题中包含某些单词. 我有下面的代码,但只能读
参见英文答案 >
Wrong mailbox items being retrieved using Exchange Web Services managed API in C#????????????????????????????????????2个
我正在尝试阅读特定的电子邮件帐户,以查找包含未读附件的项目,并在主题中包含某些单词. 我有下面的代码,但只能读取我的收件箱,而不是我要检查的收件箱 static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback=CertificateValidationCallBack; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);// .Exchange2007_SP1); service.UseDefaultCredentials = true; service.AutodiscoverUrl("bbtest@domainname.com"); //,RedirectionUrlValidationCallback); //bbtest@bocuk.local ItemView view = new ItemView(1); string querystring = "HasAttachments:true Kind:email"; //From:'Philip Livingstone' Subject:'ATTACHMENT TEST' Kind:email"; // Find the first email message in the Inbox that has attachments. // This results in a FindItem operation call to EWS. FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox,querystring,view); foreach (EmailMessage email in results) if (email.IsRead == false) // && email.HasAttachments == true { System.Diagnostics.Debug.Write("Found attachemnt on msg with subject: " + email.Subject); // Request all the attachments on the email message. //This results in a GetItem operation call to EWS. email.Load(new PropertySet(EmailMessageSchema.Attachments)); foreach (Attachment attachment in email.Attachments) { if (attachment is FileAttachment) ... 我需要更改什么才能让我的代码读取bbtest@domainname.com收件箱中的邮件? 解决方法
默认情况下,在ExchangeService对象上调用FindItems时,您的邮箱’收件箱文件夹将设置为root.假设您的域帐户具有访问其他邮箱所需的权限,则以下操作应该可以解决问题.我已经省略了服务创建部分.
//creates an object that will represent the desired mailbox Mailbox mb = new Mailbox(@"othermailbox@domain.com"); //creates a folder object that will point to inbox folder FolderId fid = new FolderId(WellKnownFolderName.Inbox,mb); //this will bind the mailbox you're looking for using your service instance Folder inbox = Folder.Bind(service,fid); //load items from mailbox inbox folder if(inbox != null) { FindItemsResults<Item> items = inbox.FindItems(new ItemView(100)); foreach(var item in items) Console.WriteLine(item); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |