我遍历Outlook中的所有电子邮件帐户。 我可以获取POP和IMAP帐户的电子邮件地址,但我没有收到MS Exchange帐户的电子邮件地址。
这是我的代码:
foreach (Outlook.Account account in accounts) {
Debug.Print("DisplayName: " + account.DisplayName);
Debug.Print("UserName: " + account.UserName);
Debug.Print("CurrentUser.Address: " + account.CurrentUser.Address); //email address or long Exchange address
Debug.Print("CurrentUser.Name: " + account.CurrentUser.Name);
Debug.Print("CurrentUser.AddressEntry.Address: " + account.CurrentUser.AddressEntry.Address);
Debug.Print("DeliveryStore.DisplayName: " + account.DeliveryStore.DisplayName);
}
以下是非Exchange帐户的结果:
DisplayName: Edgar Test Account
UserName: Edgar Tester
CurrentUser.Address: edgar@testtest.com
CurrentUser.Name: Edgar Tester
CurrentUser.AddressEntry.Address: edgar@testtest.com
DeliveryStore.DisplayName: Edgar Tester
对于Exchange:
DisplayName: User Name
UserName: 000300KJDFA6220
CurrentUser.Address: /O=FIRST ORGANIZATION/OU=EXCHANGE ADMINISTRATIVE GROUP(FYDIAASFDSFLT)/CN=RECIPIENTS/CN=00458787FA6220
CurrentUser.Name: /O=FIRST ORGANIZATION/OU=EXCHANGE ADMINISTRATIVE GROUP(FYDLKHHKLSPDLT)/CN=RECIPIENTS/CN=0054654DFA6220
CurrentUser.AddressEntry.Address: /O=FIRST ORGANIZATION/OU=EXCHANGE ADMINISTRATIVE GROUP(FYDIDADS23SPDLT)/CN=RECIPIENTS/CN=0058876220
DeliveryStore.DisplayName: User Name
(我更改了一些数字和字母以匿名化)
我想要Exchange帐户的电子邮件地址。我怎么能得到这个?
答案 0 :(得分:1)
对于Exchange帐户,请使用account.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress
。
答案 1 :(得分:0)
尝试ExchangeService.ResolveName:
//ExchangeService service; //you have some service in your code.
NameResolutionCollection nameColl = service.ResolveName(CurrentUser.Name, ResolveNameSearchLocation.DirectoryOnly,true);
稍微调整一下参数。