Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Oki, so im working on outlook .msg templates. Opening them programmatically, inserting values base on what's in my db.

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.

Thanks in advance.

like image 797
Mana Avatar asked May 22 '13 12:05

Mana


People also ask

How do I Cc multiple recipients?

In the Subject box, type the subject of the message. Enter the recipients' email addresses or names in the To, Cc, or Bcc box. Separate multiple recipients with a semicolon. To select recipients' names from a list in the Address Book, click To, Cc, or Bcc, and then click the names that you want.

How do you add multiple people to a Cc in Outlook?

You can add multiple Cc and Bcc by separating them with comma. Add the recipients in a column called "cc" for Cc recipients and "bcc" for Bcc recipients. To add multiple recipients, Cc or Bcc, just separate them with comma.

How do I send one email to multiple recipients?

In the 'To' address box, type in the first recipient's email address. Then type a comma and a space, to separate this address from the next email address. Type in the second address and continue, inserting a comma and a space between each subsequent address.


2 Answers

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();
like image 197
Ramesh Durai Avatar answered Sep 24 '22 00:09

Ramesh Durai


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.

like image 44
Geeky Guy Avatar answered Sep 24 '22 00:09

Geeky Guy