We wrote a VSTO add-on for Outlook 2010/2007.
At some point, our addin should convert text email messages to HTML from the ribbon control. This causes strange behavior in Outlook:
- We use the MailItem COM object
- We install MailItem.HTMLBody
- Email is converted to HTML, but for some reason, Times New Roman font at 10pt
The default font in Outlook is Calibri 11pt, which makes our email conversion pretty strange for the user. It works as expected when you use an existing button in Outlook to convert to HTML, but not when using our add button.
So, we tried the following:
- Set MailItem.BodyFormat ahead of time
- Wrapped our email text with
<span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'></span>(we got this idea from viewing the source of a new Outlook email)
Wrapping the tag <span>around the body of the email worked until the font changed to Calibri, but the font size remained at 10pt ...
Is there a better way to do this? Another workaround?
EDIT, working code:
if (_mailItem.BodyFormat != OlBodyFormat.olFormatHTML)
{
_mailItem.GetInspector.CommandBars.ExecuteMso("MessageFormatHtml");
}
_mailItem is Microsoft.Office.Interop.Outlook.MailItem.
source
share