2021年4月5日星期一

Outlook VSTO add-in to add watermark background

We use html table + vml rect approach to add watermark background in email. (reference: https://backgrounds.cm/)

We had a VSTO add-in, the add-in did following:

listen to ItemSend event. get HTMLBody of email. wrap body with html table + vml rect to add watermark background. set HTMLBody with new value. send it out. But we met 2 major problems that block this approach.

  1. Receiver can get watermarked email body in outlook and display watermark correctly. screenshot

But when we reply/forward this mail, the original text will become following screenshot

here is the body

    <table cellpadding='0' cellspacing='0' border='0' width='100%'>                                 <tr>                                  <td background='https://kinoiottest.blob.core.windows.net/image/watermark.png' valign='top'>                                    <!--[if gte mso 9]>                                    <v:rect xmlns:v='urn:schemas-microsoft-com:vml' fill='true' stroke='false' style='mso-width-percent:1000;'>                                      <v:fill type='tile' src='https://kinoiottest.blob.core.windows.net/image/watermark.png' />                                      <v:textbox style='mso-fit-shape-to-text:true' inset='0,0,0,0'>                                    <![endif]-->                                    <div><p class="MsoNormal">The Vector Markup Language (VML) supports the markup of vector graphic information in the same way that HTML supports the markup of textual information.&nbsp; Within VML the content is composed of paths described using connected lines and curves.&nbsp; The markup gives semantic and presentation information for the paths.<o:p></o:p></p><p class="MsoNormal"><o:p>&nbsp;</o:p></p><p class="MsoNormal">VML is written using the syntax of XML just as HTML is written using the syntax of SGML (the Standard Generalized Markup Language, [ISO 8879]) - XML is a restricted form of SGML.&nbsp; VML uses Cascading Style Sheets, Level 2 in the same way as HTML to determine the layout of the vector graphics which it contains.&nbsp; The workflow involved in rendering VML can be compared to that involved in rendering HTML as show in the following figure.<o:p></o:p></p></div>                                    <!--[if gte mso 9]>                                      </v:textbox>                                    </v:rect>                                    <![endif]-->                                  </td>                                </tr>                              </table>
  1. On sender side, it is ok to compose new mail and send, but when user reply/forward a mail, we set same body to the mail, those vml part will be converted to a image instead.

For example, we set HTMLBody with the content the same as above, the body will become like this.

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}  o\:* {behavior:url(#default#VML);}  w\:* {behavior:url(#default#VML);}  .shape {behavior:url(#default#VML);}  </style><![endif]--><style><!--  /* Font Definitions */  @font-face      {font-family:SimSun;      panose-1:2 1 6 0 3 1 1 1 1 1;}  @font-face      {font-family:"Cambria Math";      panose-1:2 4 5 3 5 4 6 3 2 4;}  @font-face      {font-family:Calibri;      panose-1:2 15 5 2 2 2 4 3 2 4;}  @font-face      {font-family:"\@SimSun";      panose-1:2 1 6 0 3 1 1 1 1 1;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal      {margin:0in;      margin-bottom:.0001pt;      font-size:11.0pt;      font-family:"Calibri",sans-serif;}  span.EmailStyle18      {mso-style-type:personal-compose;}  .MsoChpDefault      {mso-style-type:export-only;      font-family:"Calibri",sans-serif;}  @page WordSection1      {size:8.5in 11.0in;      margin:1.0in 1.0in 1.0in 1.0in;}  div.WordSection1      {page:WordSection1;}  --></style><!--[if gte mso 9]><xml>  <o:shapedefaults v:ext="edit" spidmax="1026" />  </xml><![endif]--><!--[if gte mso 9]><xml>  <o:shapelayout v:ext="edit">  <o:idmap v:ext="edit" data="1" />  </o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100%" style='width:100.0%'><tr><td valign=top style='padding:0in 0in 0in 0in'><p class=MsoNormal><img width=67 height=1722 style='width:.6979in;height:17.9375in' id="_x0000_i1025" src="cid:image001.png@01D7174B.3943F520" alt="The Vector Markup Language (VML) supports the markup of vector graphic information in the same way that HTML supports the markup of textual information.  Within VML the content is composed of paths described using connected lines and curves.  The markup gives semantic and presentation information for the paths.&#13;&#10; &#13;&#10;VML is written using the syntax of XML just as HTML is written using the syntax of SGML (the Standard Generalized Markup Language, [ISO 8879]) - XML is a restricted form of SGML.  VML uses Cascading Style Sheets, Level 2 in the same way as HTML to determine the layout of the vector graphics which it contains.  The workflow involved in rendering VML can be compared to that involved in rendering HTML as show in the following figure.&#13;&#10;"><o:p></o:p></p></td></tr></table><p class=MsoNormal><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></p></div></body></html>
https://stackoverflow.com/questions/66962206/outlook-vsto-add-in-to-add-watermark-background April 06, 2021 at 11:06AM

没有评论:

发表评论