![](/img/trans.png)
[英]C# VSTO Outlook plugin - How can I get the email address of the sender of an outgoing email using Exchange?
[英]Outlook Accounts - How to get the Exchange Email address?
我遍歷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
對於交換:
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帳戶的電子郵件地址。 我怎么能得到這個?
對於Exchange帳戶,請使用account.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress
。
試試ExchangeService.ResolveName :
//ExchangeService service; //you have some service in your code.
NameResolutionCollection nameColl = service.ResolveName(CurrentUser.Name, ResolveNameSearchLocation.DirectoryOnly,true);
稍微調整一下參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.