我有以下代码在循环中向不同的收件人发送电子邮件
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);
但我不得不恢复到第一种方法,以便我可以更改“发件人”地址
有什么想法吗?