Make ADXOlForm not visible when PrimarySmtpAddress is not within expected domains

Add-in Express™ Support Service
That's what is more important than anything else

Make ADXOlForm not visible when PrimarySmtpAddress is not within expected domains
 
Sebastien Lange




Posts: 34
Joined: 2022-09-21
Hi,

Some of my users have multiple accounts configured in their Outlook: professional and private accounts.
My add-in is developed for 3 expected professional domain names.

When a selection change occurs, or a folder switch, or whatever, I would like to show/hide ADXOlForms whether PrimarySmtpAddress is one of the 3 expected domains or not.

It should also be visible when switching to public folders but it looks PrimarySmtpAddress is correct when switching to these folders.

What is the optimal event I could listen to, in order to show/hide ADXOlForms?

Can I obtain PrimarySmtpAddress or equivalent in a more performance way than calling all the code below?


            using (var inspectors = new ComObject<Inspectors>(AddinModule.CurrentInstance.OutlookApp.Inspectors))
            using (var session = new ComObject<NameSpace>(inspectors.WrappedObject.Session))
            using (var currentUser = new ComObject<Recipient>(session.WrappedObject.CurrentUser))
            using (var addressEntry = new ComObject<AddressEntry>(currentUser.WrappedObject.AddressEntry))
            using (var exchangeUser = new ComObject<ExchangeUser>(addressEntry.WrappedObject.GetExchangeUser()))
                return exchangeUser.WrappedObject.PrimarySmtpAddress;



Note that for performance reason, Cache is set to OneInstanceForAllFolders;

Thanks beforehand

Best regards,
S?bastien
Posted 14 Dec, 2022 06:34:44 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello S?bastien,

Folders and stores (in which folders live) don't have a direct relation to the user.

The Namespace object provides the Accounts collection. BTW, you can see this collection in the UI: File | Info | Account Settings | Account Settings. Each Account has CurrentUser of its own. Namespace.CurrentUser returns Account.CurrentUser of the default account and this doesn't depend on the selection.

You can get Account.DeliveryStore and get Store.StoreId. When you switch to a folder, get MAPIFolder.StoreId (Folder.StoreId) and compare it with the StoreId associated with an account.

This approach won't work if there's no Account object associated with one of the email addresses that the user can use. Say, I have only one Account which represents my personal email address. But I also have two so-called shared mailboxes that store email correspondence for the sales and support teams here. These don't have corresponding accounts. In the case of a shared mailbox, you can try to parse the StoreID as described at http://www.add-in-express.com/forum/read.php?FID=5&TID=7498&MID=37740; find the phrase "How to get the Exchange User Address that is the owner of a specified folder". That code is based on the structure of EntryID that Microsoft published.

Also, the user can be delegated some rights on a mailbox of another user. I don't know whether this creates an Account object or not. If not, you can parse its StoreID.

Also, if a folder is a calendar folder and the folder's Folder.StoreID isn't equal to Store.StoreID of any store in the current session then the folder is another user's calendar and you can parse its StoreID. Note that in this scenario accessing some properties of the Folder object produce an exception. I expect that that would be Folder.FolderPath. But this also can be StoreID; I can't remember the property that raised an exception for me.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Dec, 2022 08:04:18 Top