Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Saving MailItem after adding user properties nulls body
Ask a questionAsk a question
 

QuestionSaving MailItem after adding user properties nulls body

  • Friday, October 30, 2009 1:20 PMCraig Dahlinger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am running into an odd scenario when modifying the mail item on a reply/reply all.  In my integration I am adding some custom user properties to a message as it arrives to the inbox.  When that message is issued a reply, I need to copy those properties/values to the new response message. The properties get added and set with no problem, but when I call mailItem.Save() on the response item, the Body property of the response item gets nulled out.  To workaround this , currently I am resetting the body/htmlbody before the save is issued.  If I do this, then the body is not nulled out on the save.  Any idea(s) why this would happen? Am I doing something wrong in the order in which I am doing things.  I basically get the response mail item from the reply/replyall event, set user properties/values and then issue a save, when I do this the body is null.

    Thanks in advance for any input, much appreciated.



    Craig Dahlinger - Software Developer

All Replies

  • Monday, November 02, 2009 9:41 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Craig,

    Welcome to MSDN forums!

    As my understanding, you question is if you save any user property programmatically when replying a message, the message body will be blank when it sent, right?

    I'm trying to narrow down this problem, as you said this is odd, so, would you please provide us some additional information about your softer environment? Which Version of Outlook is involved? Which version of VSTO are you working on?

    In your message I saw you connect this two behavior "mailItem.Save()" and "Body/HTMLBody nulled out", do you mean if you comment out the save method and the problem goes away?

    If it's possible, please provide some code snippet for us to reproduce issue, or have a more clear view on it.

    Looking forward to your feedback.

    Thanks.


    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Wednesday, November 04, 2009 6:17 AMTim LiMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello, 

     


    I am writing to check the status of the issue on your side. Could you please let me know if the suggestion works for you or not? If you have any questions or concerns, please feel free to let me know. I will be more than happy to be of assistance.


    Tim Li

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Thursday, November 12, 2009 7:16 AMCraig Dahlinger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Using Visual Studio 2008 SP1, VSTO 2007, C#


    Sorry for the late response. If I bypass the calling of the save everything is normal.  It is when I set the custom property values and issue the mailitem.save() that the body is set to null.

    For example:

    private void SetUserPropertyValueImpl(string propertyName, object propertyValue)
    {
                ItemProperty property = GetUserProperty(propertyName) ??
                                       _mailItem.ItemProperties.Add(propertyName, OlUserPropertyType.olText, true, System.Reflection.Missing.Value);
    //put a break point here, put a watch on teh _mailItem.Body
             _mailItem.Save();
    //put another break point here, the body will be null.
    }

     public ItemProperty GetUserProperty(string propertyName)
            {
                foreach (ItemProperty property in _mailItem.ItemProperties)
                {
                    if (property.Name == propertyName)
                        return property;
                }
                return null;
            }

    Craig Dahlinger - Software Developer
  • Monday, November 16, 2009 3:18 PMCraig Dahlinger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Any luck reproducing this issue, curious.  Also this is happening on the reply/reply all or forward event.
    Craig Dahlinger - Software Developer