Oki,所以我正在处理outlook .msg模板.
以编程方式打开它们,根据我的数据库中的内容插入值.
以编程方式打开它们,根据我的数据库中的内容插入值.
恩.当我想在“To”字段添加多个reciepients,而不是做如下,
mailitem.To = a + ";" + b + ";" + c;
我在下面做什么,这更简单,特别是当我在循环中做它.
mailitem.Recipients.add("a"); mailitem.Recipients.add("b"); mailitem.Recipients.add("c");
我的问题是,我也想在“CC”字段添加多个收件人,上面的功能仅适用于“To”字段.如何将多个收件人添加到“CC”字段,而无需执行字符串操作.
通常我会添加收件人到cc喜欢这样,
mailitem.CC = a + ";" + b + ";" + c;
im使用interop.outlook并从模板创建一个mailitem.
提前致谢.
解决方法
假设如果你有两个收件人列表,那么你可以这样做.
编辑:包含完整的代码.
var oApp = new Microsoft.Office.Interop.Outlook.Application(); var oMsg = (MailItem) oApp.CreateItem(OlItemType.olMailItem); Recipients oRecips = oMsg.Recipients; List<string> sTORecipsList = new List<string>(); List<string> sCCRecipsList = new List<string>(); sTORecipsList.Add("ToRecipient1"); sCCRecipsList.Add("CCRecipient1"); sCCRecipsList.Add("CCRecipient2"); sCCRecipsList.Add("CCRecipient3"); Recipients oRecips = oMsg.Recipients; foreach (string t in sTORecipsList) { Recipient oTORecip = oRecips.Add(t); oTORecip.Type = (int) OlMailRecipientType.olTo; oTORecip.Resolve(); } foreach (string t in sCCRecipsList) { Recipient oCCRecip = oRecips.Add(t); oCCRecip.Type = (int) OlMailRecipientType.olCC; oCCRecip.Resolve(); } oMsg.HTMLBody = "Test Body"; oMsg.Subject = "Test Subject"; oMsg.Send();