【发布时间】:2014-10-21 16:14:28
【问题描述】:
我们有一个 Exchange Web 服务应用程序,它在引用没有主题的电子邮件时抛出错误。
我们的自动化流程需要使用电子邮件的主题,因此代码会尝试引用它。但是,当收件箱中的电子邮件缺少主题时,我不想抛出错误,而是想更改行为。
这是我的代码:
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(common.strInboxURL);
//creates a folder object that will point to inbox fold
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
... code removed fro brevity ...
// 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(fid, searchFilterCollection, view);
if (results.Count() > 0)
{
do
{
// set the prioperties we need for the entire result set
view.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
ItemSchema.DisplayTo, EmailMessageSchema.ToRecipients,
EmailMessageSchema.From, EmailMessageSchema.IsRead,
EmailMessageSchema.HasAttachments, ItemSchema.MimeContent,
EmailMessageSchema.Body, EmailMessageSchema.Sender,
ItemSchema.Body) { RequestedBodyType = BodyType.Text };
// load the properties for the entire batch
service.LoadPropertiesForItems(results, view.PropertySet);
所以在该代码中,错误被抛出到最后一行service.LoadPropertiesForItems(results, view.PropertySet); 上的复杂属性get。
所以,我知道我将不得不在这里执行类似Try..Catch 的操作,但是,我需要先检查邮件项目的主题属性是否存在,然后才能引用它以查看它是什么——一些一种鸡和蛋的问题。
如果没有主题,我需要将邮件标记为已读,向团队发送警告邮件,然后继续处理邮箱中的下一封未读邮件。
任何有关解决此问题的最佳方法的建议都将不胜感激。
谢谢
【问题讨论】:
标签: c# email exchangewebservices exchange-server-2010