C#VSTO加载 - 转换纯文本电子邮件,HTML加载、文本、电子邮件、VSTO

2023-09-05 01:38:33 作者:浅笑〃掩不了忧伤

我们已经写了VSTO插件用于Outlook2007分之2010。

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

在一个点上,我们的插件必须纯文本邮件转换为HTML从功能区控制。这将导致Outlook中一些奇怪的行为:

At one point, our addin must convert plain text emails to HTML from a ribbon control. This causes some strange behavior in Outlook:

我们正在使用的MailItem COM对象 我们设置MailItem.HTMLBody 电子邮件转换为HTML,但由于某些原因,字体为宋体,在10PT

在Outlook中的默认字体是宋体11磅,这使得我们的电子邮件转换一下pretty的怪给用户。它的工作原理,当你在Outlook中使用现有的按钮来转换为HTML预期,但使用我们的插件的按钮时没有。

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:

设置MailItem.BodyFormat时间提前 在包裹我们的电子邮件文本:&LT;跨度风格='字体大小:11.0pt;字体家庭:宋体,无衬线'&GT;&LT; / SPAN&GT; (我们得到了这个想法从观看一个新的Outlook电子邮件的来源) 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)

中包装&LT;跨度&GT; 围绕电子邮件正文标签的工作就改变字体为宋体,但字体大小住在10PT ...

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?

编辑,工作code:

        if (_mailItem.BodyFormat != OlBodyFormat.olFormatHTML)
        {
            _mailItem.GetInspector.CommandBars.ExecuteMso("MessageFormatHtml");
        }

_mailItem是Microsoft.Office.Interop.Outlook.MailItem。

_mailItem is a Microsoft.Office.Interop.Outlook.MailItem.

推荐答案

您有两种方式:

在点击的编程方式通过内置按钮Inspector.CommandBars.ExecuteMso(MessageFormatHtml) 关闭检查,转换消息格式,保存邮件,并重新打开它。