我有以下代码循环发送电子邮件给不同的收件人
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();
}
Run Code Online (Sandbox Code Playgroud)
然而,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);
Run Code Online (Sandbox Code Playgroud)
但我必须恢复到第一种方法,以便我可以更改“发件人”地址
有什么想法吗?
我有一个字典,其键包含字符串列表。
Dictionary<string, List<string>> keyValueListDict=new Dictionary <string,List<string>>();
List<string>valueList = new List<string>();
Run Code Online (Sandbox Code Playgroud)
我的keyValueListDict充满了独特的键和值列表。对于每个字典条目,我需要输出键,后跟列表的内容(值)。
更新:我认为问题出在输入值所以我正在从我的数据库检索一个对象
foreach(object)
{
key=object.key;
foreach(string value in object.othercomponent)
{
list.add(value);
}
keyValueListDict.add(key,list);
list.clear();
}
Run Code Online (Sandbox Code Playgroud)
每次清除列表时,列表中值的计数都会重置为 0,以便我可以为下一个对象填充它,但我不知道如何避免这种情况