How to: Specify Different Recipient Types for a Mail Item

Office 2013 and later

This example shows how to programmatically set different recipient types (To, Cc, or Bcc) for a mail item.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

The following code example illustrates how to specify whether a recipient of a MailItem object is a To, Cc, or Bcc recipient. SetRecipientTypeForMail creates a MailItem object, adds three Recipient objects to the Recipients collection of the MailItem, and then sets the Type property of each Recipient object to a value from the OlMailRecipientType enumeration.

Note Note

The Type property of the Recipient object is an int type and does not correlate to a specific recipient type enumeration.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void SetRecipientTypeForMail()
    Outlook.MailItem mail = Application.CreateItem(
        Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Sample Message";
    Outlook.Recipient recipTo =
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;

Other resources