PrOjEkTeD
PrOjEkTeD

Reputation: 161

Html not showing up in outlook mail

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?

Upvotes: 6

Views: 2607

Answers (3)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

mailItem.Body = body;

That is because you use the Body property. Use the HTMLBody instead.

Upvotes: 4

rory.ap
rory.ap

Reputation: 35318

Try using mailItem.HTMLBody = Body; instead of mailItem.Body = body;, and then add mailItem.BodyFormat = olFormatHTML;

Upvotes: 4

Dipiks
Dipiks

Reputation: 3928

mailItem.IsBodyHtml= true;

will do what you want if I understand your problem

Upvotes: 3

Related Questions