I have the following code that is sending emails to different recipients in a loop
public void SendMail2(string subject, string body, string emailAddress, string cc)
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = subject;
mailItem.To = emailAddress;
mailItem.CC = cc;
mailItem.Body = body;
mailItem.SentOnBehalfOfName = "name";
mailItem.Display(false);
mailItem.Send();
}
However the html is just showing up as text with all the tags in the email, while it was perfect when i was using
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
but I had to revert back to the first method so i can change the "From" address
Any ideas please?
mailItem.Body = body;
That is because you use the Body property. Use the HTMLBody instead.
Try using mailItem.HTMLBody = Body;
instead of mailItem.Body = body;
, and then add mailItem.BodyFormat = olFormatHTML;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With