如何将多个收件人添加到mailitem.cc字段c#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16691888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add multiple recipients to mailitem.cc field c#
提问by Mana
Oki, so im working on outlook .msg templates. Opening them programmatically, inserting values base on what's in my db.
好的,所以我正在研究 Outlook .msg 模板。以编程方式打开它们,根据我的数据库中的内容插入值。
ex. when i want to add multiple reciepients at "To" field, instead of doing as following,
前任。当我想在“收件人”字段添加多个收件人时,而不是执行以下操作,
mailitem.To = a + ";" + b + ";" + c;
i do whats below, which is simpler, especially when i'm doing it in a loop.
我做下面的事情,这更简单,尤其是当我在循环中进行时。
mailitem.Recipients.add("a");
mailitem.Recipients.add("b");
mailitem.Recipients.add("c");
My problem is, i also want to add multiple recipients at "CC" field and the function above only works for "To" field. How can i add multiple recipients to "CC" field without having to do string manipulation.
我的问题是,我还想在“抄送”字段中添加多个收件人,而上述功能仅适用于“收件人”字段。如何将多个收件人添加到“抄送”字段而无需进行字符串操作。
normally i would add recipients to cc like so,
通常我会像这样将收件人添加到抄送,
mailitem.CC = a + ";" + b + ";" + c;
im using interop.outlook and creating an mailitem from template.
我正在使用 interop.outlook 并从模板创建一个邮件项。
Thanks in advance.
提前致谢。
采纳答案by Ramesh Durai
Suppose If you have two Listof recipients, then you can do like this.
假设如果您有两个List收件人,那么您可以这样做。
Edit: Included full code.
编辑:包括完整的代码。
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();

