Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


C#
//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;



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:

XML
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!
Posted
Comments
Thomas ktg 6-Sep-13 3:12am    
Use the HTMLBody to assign the strings generated instead of Body.

oMsg.HTMLBody = " your generated strings";

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900