简体   繁体   中英

Incorrect format of email address from CurrentUser.Address in Outlook VSTO

I am trying to get the current user's Outlook email address with

 Globals.ThisAddIn.Application.Session.CurrentUser.Address;

The value this displays is somewhat like this:

"/o=ExchangeLabs/ou=Exchange Administrative Group (xxxxxxxxx)/cn=Recipients/cn=xxxxxxxxxxxxxxxxx-[the beginning of my email address is here]"

The first problem is that the email address is cut off. I at first thought that this is a breakpoint issue, but after modifying the string I found it's just cut off by default. The second is that I only want the email address value without all the data before. I could edit out the string but I'm looking for the proper way of getting the value.

This works when the user logs in via Exchange.

Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;

I'm looking for the equivalent for users not logged in via Exchange.

I found Email Address of the Current User but it is an old thread and the solutions all seem pretty hacky.

Check the AddressEntry.Type property. If it is "EX", use GetExchangeUser().PrimarySmtpAddress . Otherwise just read the Address property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM