How to add multiple recipients to mailitem.cc field c#

十年热恋 提交于 2019-12-05 01:27:55

Suppose If you have two List of recipients, then you can do like this.

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

Use the Recipients property as documented here (look for the second example). you can add a lot of people to the collection and then change the destination type from to to CC.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!