将HTML内容导入电子邮件 [英] Importing HTML content into an email message

查看:168
本文介绍了将HTML内容导入电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在构建一个应用程序来生成一些电子邮件,我正在努力将我们的公司页脚(以html格式保存)插入这些生成的电子邮件。





Hi all,

I'm building an app to generate some emails and i'm struggling inserting our company footer (saved in html format) into these generated emails.


//have a for loop that cycles through each mail to be generated
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
			{

// Create the Outlook application by using inline initialization.
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
 MailItem oMsg = (MailItem)oApp.CreateItem(OlItemType.olMailItem);

 oMsg.BodyFormat = OlBodyFormat.olFormatHTML;



                 using (StreamReader reader = File.OpenText(@"C:\Users\william-k\AppData\Roaming\Microsoft\Signatures\Pretoria 1.htm"))
                 {
                     oMsg.HTMLBody = reader.ReadToEnd();

                 }
                 
                oMsg.Subject = dataGridView1.Rows[i].Cells["Case Number"].Value.ToString() + ' ' + dataGridView1.Rows[i].Cells["Catchword"].Value.ToString() + " / Renewal Reminder";
                oMsg.Body = oMsg.Body = "Dear Sirs " + Environment.NewLine + Environment.NewLine + "Our  attached for your kind attention."
                    + Environment.NewLine + Environment.NewLine + "Kind Regards" + Environment.NewLine + "me" + oMsg.HTMLBody;







但是当生成邮件时,它会显示html源代码的实际标签,而不是以正确的HTML格式对其进行格式化。

示例:






But when the mail is generated it shows the actual tags of the html source instead of formatting it in the proper HTML format.
Example:

Kind Regards

<HTML xmlns:o="urn:schemas-microsoft-com:office:office"><HEAD><!-- Signature generated by Exclaimer Signature Manager on {Current Date} --></HEAD>
<BODY>
<P>
<TABLE style="WIDTH: 100%" cellSpacing=1 cols=1 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD><span style='font-family:Calibri; font-size:small; color: Black; font-weight: bold; '>William Kruger</span></TD></TR>
  <TR>
    <TD><span style='font-family:Calibri; font-size:x-small; font-weight: bold; '>System Specialist</span></TD></TR>





等....





我们非常感谢任何帮助!



etc....


Any help would be much appreciated!

推荐答案

使用 [MSDN] MailItem.HTMLBody属性(Outlook) [ ^ ]分配html。
Use [MSDN] MailItem.HTMLBody Property (Outlook)[^] to assign a html.


这篇关于将HTML内容导入电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆