简体   繁体   English

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

[英]C# Office / Outlook 2010 Toolbar - HTML Emails - HTMLBody is slow

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: 我正在编程一个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();

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. 在Outlook 2003/2007中这是可以的,但在2010中则是如此。我已经意识到Outlook在电子邮件中添加了很多糟糕的代码(MSO样式,重新格式化html以及许多其他废话),但这实际上非常慢。 I thought about forcing outlook to add the crap code to the saved HTML files, I've tried this: 我考虑过强迫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;

But the "content" variable still contains the originally formatted HTML. 但是“ content”变量仍然包含原始格式的HTML。 Is this the right direction? 这是正确的方向吗? How can I get reformatted HTML with the outlook code? 如何使用Outlook代码重新格式化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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM