Html 没有出现在 outlook 邮件中

Html not showing up in outlook mail

我有以下代码循环发送电子邮件给不同的收件人

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();
    }

然而 html 只是显示为电子邮件中所有标签的文本,而当我使用

时它是完美的
        // 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); 

但我不得不恢复到第一种方法,以便我可以更改 "From" 地址

有什么想法吗?

mailItem.IsBodyHtml= true;

如果我理解你的问题,我会做你想做的事

尝试使用 mailItem.HTMLBody = Body; 而不是 mailItem.Body = body;,然后添加 mailItem.BodyFormat = olFormatHTML;

mailItem.Body = body;

那是因为您使用了 Body property. Use the HTMLBody