none
Outlook mail item is getting broken after reading property with PropertyAccessor RRS feed

  • Question

  • I created an add-in for MS Outlook which simply shows some email headers info. The command for showing header info is accessible from a selected email item's context menu. Everything is good until I setup a delivery rule for sending emails. Every email is staying in outbox folder for a 2 minutes and getting sent after that. But when I'm selecting a email item it getting regular font (untouched is bold and italic) and losing it sent datetime field value and showing as "none". After that the email is staying in outbox folder without sending.

    I found a code part which causing a such behavior

    string header = (string)mailItem
         .PropertyAccessor
         .GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

    So I'm seeing that a simple GetProperty operation breaks the outbox email item state. I was unable to find any info related to the above mentioned behavior and didn't know how to fix this. So my question is how to fix this issue and why such a behavior is happening ?


    Wednesday, April 23, 2014 8:54 AM

Answers

  • You should never do any accesses on items in Outbox that have been submitted to the mail transport. That will break things, even if it's just a read access.

    Ken Slovak MVP - Outlook

    Wednesday, April 30, 2014 5:50 PM
    Moderator

All replies

  • Hi,

    I'm moving this thread to Outlook for Developers forum so that you can get support specific to code.

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Thanks,

    Melon Chen

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here
    Thursday, April 24, 2014 2:00 AM
  • Hi David,

    I'm not sure if it will solve your problem, but I think it worth trying:

    Instead of using ObjectA.ObjecB.Method(), please explicitly set objectB, and then release it (using Marshal.ReleaseCOMObject).

    In your example:
    PropertyAccessor PA = mailItem.PropertyAccessor;
    String header = (string)PA.GetProperty("...");
    Marshal.ReleaseCOMObject(PA);

    I would also advice to check the entire code for more unreleased objects, and to release them.

    Hope it helps,
    Moshe

    Thursday, April 24, 2014 6:48 AM
  • Hello David,

    Where do you run the problematic line of code? Is it the ItemSend event handler? If so, I'd recommend to move your code to another event handler - for example, you may intercept the Send button click and etc.

    string header = (string)mailItem
         .PropertyAccessor
         .GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

    Note, the line of code contains a chain of calls. I'd suggest declaring each property or method call on a separate line. Thus, you will be able to find the problematic property or method call.

    Finally, I have noticed that you don't release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN.

    Thursday, April 24, 2014 11:50 AM
  • Actually I did Release, just not showed on sample code. But anyway it didn't helped.
    Wednesday, April 30, 2014 7:53 AM
  • Can you show ALL of your code please David?  Also, are you running additional code after you show the header info?  Are you touching the email in the Outbox?  Do they symptoms occur when you disable any delivery rules that may be interacting with the affected emails?

    Eric Legault (MVP: Outlook; About me)
    Outlook Appins: Store social media fields in your Outlook Contacts!
    Co-author, Microsoft Office 2013 Professional Step-By-Step

    Wednesday, April 30, 2014 4:59 PM
    Moderator
  • You should never do any accesses on items in Outbox that have been submitted to the mail transport. That will break things, even if it's just a read access.

    Ken Slovak MVP - Outlook

    Wednesday, April 30, 2014 5:50 PM
    Moderator
  • You should never do any accesses on items in Outbox that have been submitted to the mail transport. That will break things, even if it's just a read access.

    Ken Slovak MVP - Outlook


    Thanks Ken. I guessed that was the reason. So I did check if mail item sent property is set to false. I searched over the Internet but did not manage to find some info related to the behavior you mentioned. If you can provide some links that will be great. It is very weird that even GetProperty() operation which I guess must just read property is broking the mail item marked for submission.
    Wednesday, April 30, 2014 6:08 PM
  • There are a number of references on this type of thing, for example http://www.slipstick.com/problems/after-viewing-outlooks-outbox-the-messages-in-it-wont-send/.

    Just reading the item or opening it when it's been submitted will prevent the item from being sent. Checking the Sent property will also do the same thing. The best assumption is if it's in Outbox leave it alone.

    Sent isn't set until the item is actually sent out, so it won't be set in submitted messages until after they go out. The correct property for that is Submitted, but reading that using anything other than Extended MAPI or Redemption (www.dimastr.com/redemption) on an RDOMail will also unsubmit the item.


    Ken Slovak MVP - Outlook

    Wednesday, April 30, 2014 7:54 PM
    Moderator
  • There are a number of references on this type of thing, for example http://www.slipstick.com/problems/after-viewing-outlooks-outbox-the-messages-in-it-wont-send/.

    Just reading the item or opening it when it's been submitted will prevent the item from being sent. Checking the Sent property will also do the same thing. The best assumption is if it's in Outbox leave it alone.

    Sent isn't set until the item is actually sent out, so it won't be set in submitted messages until after they go out. The correct property for that is Submitted, but reading that using anything other than Extended MAPI or Redemption (www.dimastr.com/redemption) on an RDOMail will also unsubmit the item.


    Ken Slovak MVP - Outlook

    I understand. I will modify my code and will change the usage of Sent property. But the strange thing here that after I used the Sent property the issue was gone.

    I did the following and it started to work as it must without any issue:

    if (mailItem.Sent) { string header = (string)mailItem .PropertyAccessor .GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E"); }

    Thanks a lot for provided link.


    Wednesday, April 30, 2014 8:10 PM
  • May I see your code?
    Thursday, May 1, 2014 10:03 AM
  • May I see your code?

    Sure,

    Here is the extension method:

    public static string HeaderString(this MailItem mailItem)
    {
        try
        {
            string header = string.Empty;
            if (mailItem.Sent)
            {
                PropertyAccessor propertyAccessor = mailItem.PropertyAccessor;
                header = (string)propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E"); 
            }
     
            return header;
        }
        catch (Exception ex)
        {
            //...
        }
    }
     

    Just for note. The caller method doing a Release after getting header string.

    Monday, May 5, 2014 12:29 PM
  • And where do you release an instance of the PropertyAccessor class? ;)

    It can be a potential cause of the issue you faced with.

    Monday, May 5, 2014 12:33 PM