从 Outlook 中的 globalAddressList 中检索电子邮件地址

Retrieving email address from a globalAddressList in outlook

根据 AddressEntry.Address 属性 的描述,我希望 "return a String (string in C#) representing the e-mail address of the AddressEntry."

  Outlook.AddressList gal = Application.Session.GetGlobalAddressList();
  Outlook.AddressEntries ae = gal.AddressEntries;
  List<string> email = new List<string>();

  foreach (Outlook.AddressEntry e in ae)
  {
      email.Add(e.Address);
  }

相反,电子邮件列表充满了看起来像...

"/o=companyName/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=firstname.lastname"

我更喜欢它 return 类似....

firstname.lastname@mycompany.com

我怎么用错了?

如果 AddressEntry.Type == "EX",则使用 AddressEntry.GetExchangeUser().PrimarySmtpAddress。准备好处理空值和异常。