开发者

C# VSTO Add-in - Convert plain text email to HTML

We have written a VSTO addin for Outlook 2010/2007.

At one point, our addi开发者_如何学JAVAn must convert plain text emails to HTML from a ribbon control. This causes some strange behavior in Outlook:

  1. We're using the MailItem COM object
  2. We set MailItem.HTMLBody
  3. Email is converted to HTML, but for some reason the font is Times New Roman at 10pt

The default font in Outlook is Calibri 11pt, which makes our email conversion look pretty strange to the user. It works as expected when you use the existing button in Outlook to convert to HTML, but not when using our addin's 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 <span> tag around the email body worked as far as changing the font to Calibri, but the font size stayed 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 a Microsoft.Office.Interop.Outlook.MailItem.


You have two ways:

  1. "Click" the built-in button programmatically via Inspector.CommandBars.ExecuteMso("MessageFormatHtml")
  2. Close the inspector, convert the message format, save the email and re-open it.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜