共用方式為


為郵件專案指定不同的收件者類型

此範例示範如何以程式設計方式設定郵件專案 (收件者、副本或密件抄送) 的不同收件者類型。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

下列程式代碼範例說明如何指定 MailItem 物件的收件者是收件者、副本收件者或密件抄送收件者。 SetRecipientTypeForMail 會建立 MailItem 物件、將三個 Recipient 物件新增至 MailItemRecipients 集合,然後將每個 Recipient 物件的 Type 屬性設定為 OlMailRecipientType 列舉中的值。

注意事項

Recipient 物件的 Type 屬性是 int 類型,而且不會與特定收件者類型列舉相互關聯。

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 =
        mail.Recipients.Add("someone@example.com");
    recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
    Outlook.Recipient recipCc =
        mail.Recipients.Add("someonecc@example.com");
    recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
    Outlook.Recipient recipBcc =
        mail.Recipients.Add("someonebcc@example.com");
    recipBcc.Type = (int)Outlook.OlMailRecipientType.olBCC;
    mail.Recipients.ResolveAll();
    mail.Display(false);
}

另請參閱