none
Object not found in store error when trying to load MimeContent of an email (containing attachments) RRS feed

  • Question

  • This is a weird one and I'm hoping someone can reproduce this and give me some help.

    We have a system that uses the EWS Managed API to send emails. Optionally an email may need to be saved out as an rfc822 (.eml) file afterwards for storing in our own database. In order to save to a file I need to load up the MimeContent of the message. And this is where an "Object not found in store" exception can get thrown.

    The really strange part is that the exception only seems to occur if the email contains an attachment and if there is too much of a delay between sending the email and trying to access the MimeContent!

    My test code is something like:

    // Set up the basics _item = new EmailMessage(P7ExchangeService.Service); _item.Subject ="Hello world"; _item.ToRecipients.Add("some name", "test@test.com"); _item.Body = new MessageBody(BodyType.HTML, @"<html><head></head><body>hello world<image src=""cid:blah""/></body></html>"); // Add attachment FileAttachment att = _item.Attachments.AddFileAttachment("blah", "c:\temp\blah.jpg"); att.IsInline = true; att.ContentId = "blah"; // Send and save _item.SendAndSaveCopy(); // Wait a bit (see comments below) Thread.Sleep(5000); // Now try and save out var propCollection = _item.GetLoadedPropertyDefinitions(); propCollection.Add(ItemSchema.MimeContent); _item.Load(new PropertySet(propCollection)); // EXCEPTION!

    // ... etc

    On some systems it seems that the sending can take a while, hence my Thread.Sleep() call to simulate this.

    Its when I try and load up the MimeContent that I will then get the exception. But ONLY if I sleep (simulating the occasional delay seen on customer sites) and ONLY if the email contains an attachment.

    The mimecontent is necessary in order to save out to a file (by accessing the _item.MimeContetn property).

    Can someone please explain the exception and/or provide a better way of doing this??

    Wednesday, May 21, 2014 10:54 AM

Answers

All replies

  • More random information:

    It makes no difference if the attachment is inline or a 'normal' attachment.

    A delay of 1 second causes the issue, but half a second appears to work.

    This is just bizarre and the situation is getting desperate. Anyone?

    Wednesday, May 21, 2014 2:50 PM
  • This is normal EWS doesn't return the Id of the Item in the SentItems Folder so you need to use a workaround like http://blogs.msdn.com/b/exchangedev/archive/2010/02/25/determining-the-id-of-a-sent-message-by-using-extended-properties-with-the-ews-managed-api.aspx .

    If you want to understand the issue you can enable tracing and look at responses, the actually Id your trying to load the MimeContent from is probably the Id of the draft message. Eg to send a message via EWS with attachments multiple operations must be used to construct it and when the messages finally gets sent the copy in the drafts folder is deleted and a copy is created in the SentItems folder. However the Id isn't returned for the SentItems copy hence you need the workaround.

    Cheers
    Glen

    • Marked as answer by RJP1973 Thursday, May 22, 2014 10:42 AM
    Thursday, May 22, 2014 6:38 AM
  • Glen, you're a lifesaver!

    Thursday, May 22, 2014 10:42 AM