取得收件者的電子郵件位址
此範例示範如何取得收件者的簡易郵件傳輸通訊協定 (SMTP) 位址。
範例
在下列程式代碼範例中,GetSMTPAddressForRecipients 方法會採用 MailItem 對象作為輸入自變數,然後顯示該郵件專案每個收件者的 SMTP 位址。 方法會先擷取 Recipients 集合,代表為郵件專案指定的收件者集合。 針對該 Recipients 集合中的每個 Recipient,方法接著會取得對應至該 Recipient 物件的 PropertyAccessor 物件。 最後,方法會使用 PropertyAccessor 屬性來取得 MAPI 屬性的值,該屬性 https://schemas.microsoft.com/mapi/proptag/0x39FE001E
會對應至收件者的 PR_SMTP_ADDRESS (PidTagSmtpAddress) 屬性。
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 GetSMTPAddressForRecipients(Outlook.MailItem mail)
{
const string PR_SMTP_ADDRESS =
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
Outlook.Recipients recips = mail.Recipients;
foreach (Outlook.Recipient recip in recips)
{
Outlook.PropertyAccessor pa = recip.PropertyAccessor;
string smtpAddress =
pa.GetProperty(PR_SMTP_ADDRESS).ToString();
Debug.WriteLine(recip.Name + " SMTP=" + smtpAddress);
}
}