使用项ID在Exchange服务器上找不到邮件项

时间:2014-05-14 13:37:09

标签: c# email exchangewebservices exchange-server-2010

我的应用程序已经运行了好几周,基本上它会轮询Exchange 2010邮件服务器邮箱以获取新邮件,获取每个邮件和任何附件的详细信息,并使用该信息创建案例(带附件)在SalesForce CRM上。

在通过电子邮件创建每个案例后,必须使用存储的项目ID从Exchange检索电子邮件并调用属性集,将电子邮件标记为读取

几周以来一直运行良好,甚至从Exchange获得一些额外的属性,例如我可以在会话日志中使用的 Subject,From,To 属性。

今天突然间,如果我尝试包含 PropSet ,则Exchange不会从 itemID 返回邮件 - 如果我省略PropSet则工作正常。

这是代码:

try
    {
    //creates an object that will represent the desired mailbox
    Mailbox mb = new Mailbox(common.strInboxURL); // new Mailbox(targetEmailAddress); @"bbtest@bocuk.local"

    //creates a folder object that will point to inbox fold
    FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);

    //this will bind the mailbox you're looking for using your service instance
    Microsoft.Exchange.WebServices.Data.Folder inbox = Microsoft.Exchange.WebServices.Data.Folder.Bind(service, fid);

    // As a best practice, limit the properties returned to only those that are required.
    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly,
    ItemSchema.Subject, EmailMessageSchema.IsRead, EmailMessageSchema.Sender, EmailMessageSchema.DateTimeReceived);

    // Bind to the existing item by using the ItemId.
    // This method call results in a GetItem call to EWS.
    EmailMessage mail = EmailMessage.Bind(service, itemId); //, propSet);

    if (!mail.IsRead) // check that you don't update and create unneeded traffic
    {
        mail.IsRead = true; // mark as read
        mail.Update(ConflictResolutionMode.AutoResolve); // persist changes
    }

    mail.Update(ConflictResolutionMode.AlwaysOverwrite);
    e2cSessionLog("\tcommon.MarkAsRead", "email Item ID: " + itemId);

//e2cSessionLog("\tcommon.MarkAsRead", "MARKED AS READ email Subject: " + mail.Subject.ToString() + "; From: " + mail.Sender.Name, mail.DateTimeReceived.ToString());

    return true;

}

catch (Exception ex)
{
    string innerException = "";
...

请注意,在EmailMessage mail = EmailMessage.Bind(service, itemId); //, propSet);行中,我现在省略了PropSet参数,现在它可以正常工作。

但为什么?

为了始终使用Item ID返回的邮件返回属性,我还需要做些什么吗?

有什么想法吗?

0 个答案:

没有答案