C# Office / Outlook 2010 工具栏 - HTML 电子邮件 - HTMLBody 速度很慢

发布于 2024-11-06 13:11:11 字数 1061 浏览 1 评论 0原文

我正在编写一个 Outlook 工具栏,它从网站下载一些电子邮件模板,然后允许从准备好的 html 文件创建 html 电子邮件,这是我用于创建电子邮件的代码:

        MailItem letter = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
        letter.HTMLBody = @"<div style=""text-align:center""> <b><br/>Please wait for content to be loaded...</b></div>";            
        letter.Display(false);
        letter.BodyFormat = OlBodyFormat.olFormatHTML;
        letter.HTMLBody = buffer.ToString();

这在 Outlook 2003/2007 中没问题,但在 2010 年却很慢。 我意识到 Outlook 在电子邮件中添加了很多蹩脚代码(MSO 样式、重新格式化 html 和许多其他废话),而且这实际上非常慢。我考虑过强制 Outlook 将垃圾代码添加到保存的 HTML 文件中,我已经尝试过:

            // Compile the file and add the MSO Crap
            MailItem letter = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
            letter.BodyFormat = OlBodyFormat.olFormatHTML;
            letter.HTMLBody = content;
            content = letter.HTMLBody;

但是“content”变量仍然包含最初格式化的 HTML。这是正确的方向吗?如何使用 Outlook 代码重新格式化 HTML?

I'm programming an outlook toolbar that downloads some email templates from the website and then allows creating html emails from prepared html files, This is the code I use for creating an email:

        MailItem letter = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
        letter.HTMLBody = @"<div style=""text-align:center""> <b><br/>Please wait for content to be loaded...</b></div>";            
        letter.Display(false);
        letter.BodyFormat = OlBodyFormat.olFormatHTML;
        letter.HTMLBody = buffer.ToString();

This is OK in outlook 2003/2007 but so slow in 2010.
I've realized that outlook add lots of crappy code to the email (MSO styles, reformats html and lots of other crap), and this is actually very slow. I thought about forcing outlook to add the crap code to the saved HTML files, I've tried this:

            // Compile the file and add the MSO Crap
            MailItem letter = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem);
            letter.BodyFormat = OlBodyFormat.olFormatHTML;
            letter.HTMLBody = content;
            content = letter.HTMLBody;

But the "content" variable still contains the originally formatted HTML. Is this the right direction? How can I get reformatted HTML with the outlook code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守护在此方 2024-11-13 13:11:11

我会回答我自己的问题...

public static string HtmlToCrap(String HtmlSource)
{
string HtmlFile = "";
System.IO.File.WriteAllText(HtmlFile, HtmlSource);


Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();

oDoc = oWord.Documents.Add();
oWord.Visible = false;

oDoc = oWord.Documents.Open(HtmlFile);

oDoc.SaveAs(@"C:\WORDhtml.html", Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML);

oDoc.Close(false);
oWord.Quit();

return ReadFile(@"C:\WORDhtml.html");
}

I will answer my own question...

public static string HtmlToCrap(String HtmlSource)
{
string HtmlFile = "";
System.IO.File.WriteAllText(HtmlFile, HtmlSource);


Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document();

oDoc = oWord.Documents.Add();
oWord.Visible = false;

oDoc = oWord.Documents.Open(HtmlFile);

oDoc.SaveAs(@"C:\WORDhtml.html", Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML);

oDoc.Close(false);
oWord.Quit();

return ReadFile(@"C:\WORDhtml.html");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文