none
Disappearing HTML Comments in Outlook Add-In Mail Body RRS feed

  • Question

  • I have created an Add-In that inserts text in a mailItem.HTMLBody, along with an HTML comment that I later search for and create an index of all occurrences of that string - however, whenever I modify the email body after the text has been inserted, the HTML comments disappear.  I am guessing that Outlook re-constructs the HTMLBody every time new text is added?  Is there a better way to create an identifier of a particular string while maintaining the ability to format the font properties of a string?

    Here is the string that I am searching for:

    ClassificationStringTop = "<!--ClassificationTag--><span style='font-family:Times-New-Roman;'><big>Classification: <font color='red'><b>" + ClassificationType.ToUpper() + "</big></b></font></span><br><br><!--EndClassificationTag-->";

    Thanks for the help!

    Monday, July 23, 2012 12:32 PM

Answers

All replies

  • maybe try adding custom attribute to encompasing <span> element. I have not tried it myself so i have no idea if word's editor will also not remove it. Something like: <span style='font-family:Times-New-Roman;' mycustomtag='custom value'>

    Monday, July 23, 2012 12:49 PM
  • Thanks for the quick response!  I just gave that a try, seems to have the same problem.
    Monday, July 23, 2012 1:03 PM
  • try maybe adding custom header element, maybe this will be left alone. Otherwise i guess you will have to resort to using UserProperties on MailItem. Or do you want those custom values to be sent to recipients?
    Monday, July 23, 2012 1:08 PM
  • I just tried adding a header, same problem still occurs.  I do have a custom user property for the general classification of the email, but I want to be able to index all instances of the string within the email so that I can modify/remove them separately.  
    Monday, July 23, 2012 1:20 PM
  • i really have no idea how to preserve your custom info inside mail's body. Outlook assumes it controls it completely and reformats it any way it wants. try maybe using inline css classes that do nothing and apply them to specific html elements, maybe outlook will leave them alone.
    Monday, July 23, 2012 5:58 PM
  • Is there another way of adding text (with font styles applied) at specific locations in the mail body?  I am trying to add text banners at the top and bottom of emails, but also want to keep track of existing banners in forward or reply emails.
    Tuesday, July 24, 2012 1:59 PM
  • yes, you can use Word API to manipulate contents of mail's body from outlook 2007 onward
    Tuesday, July 24, 2012 8:35 PM
  • Thanks, will give that a try!
    Monday, July 30, 2012 1:10 PM