Html not showing in Outlook

I have the following code that sends letters to various 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, html just displayed as text with all the tags in the letter, while it was perfect when I used

        // 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 go back to the first method, so I can change the address from

Any ideas please?

+4
source share
3 answers

Try using mailItem.HTMLBody = Body;instead mailItem.Body = body;, then addmailItem.BodyFormat = olFormatHTML;

+3
source

mailItem.Body = body;

This is because you are using the Body property . Use HTML code instead .

+4
source
mailItem.IsBodyHtml= true;

, ,

+3

All Articles