0

I have an application that has been working fine for several weeks, basically it polls an Exchange 2010 mail server mailbox for new messages, gets the details of each one and any attachments, and use that information to create cases (with attachments) on the SalesForce CRM.

After each case is created from the email, the email must be marked as read by retrieving it from Exchange using the stored Item ID and calling the property set.

For several weeks this has been working fine, even getting some extra properties from Exchange such as the Subject, From, To properties which I can use in the session log.

Suddenly today the mail isn't being returned by Exchange from the itemID if I try to include the PropSet - if I omit the PropSet it works fine.

here is the code:

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 = "";
...

notice that in the line EmailMessage mail = EmailMessage.Bind(service, itemId); //, propSet); I have now omitted the PropSet argument and it now works.

But why?

Is there something else I need to do in order to always get the properties back with the mail returned using Item ID?

Any thoughts?

Abhitalks
  • 27,721
  • 5
  • 58
  • 81
Our Man in Bananas
  • 5,809
  • 21
  • 91
  • 148
  • What is the error code you are getting when you add the propset? – pjneary May 15 '14 at 13:33
  • 1
    It would have been better to see the exception. I suspect the propSet definition isn't valid. Try using EmailMessageSchema.Subject instead of ItemSchema.Subject – Andy May 19 '14 at 15:40
  • @Andy: the qweird thing is it works for every other email - it was just one email on one day and now I can't reproduce the error – Our Man in Bananas May 20 '14 at 08:29

0 Answers0