Sample Extended MAPI application for updating the account and Outlook store name following an SMTP address change.
The tool can only run alongside Outlook, as Outlook's MAPI is used to operate the changes to the profile. If Outlook is running at the time the executable is run, it will need to be restarted.
If connecting to Active Directory, the old SMTP address, currently set as the display name of the account or store, must be present as a secondary SMTP address in order for the search to succeed and the account or store to be updated. If the SMTP address no longer exists, the update will fail and the account or store name will remain the same.
How it works
This is a follow up post for Outlook Code: Change the name of the root folder in Outlook 2010 after an SMTP address change. Whilst the sample add-in that I've published at that time renamed the root folder in a simple and efficient way, it wasn't possible to change the Account name, for which reason Outlook users were seeing their old SMTP address in the Mail From field in Outlook which seemed to cause a lot of confusion. To address that, I have written a sample application that updates both the Account name and the root folder display name.
The sample uses Extended MAPI for logging on to the default profile and updating the default store display name (root folder), the Account Management API to access the default account and update the name and the Active Directory Service Interfaces to connect to Active Directory and retrieve the Primary SMTP address corresponding to the SMTP address set as the default account name.
Usage: ProfileAccountUpdateTool [-?] [-ad] [-dc dcname] [-pm <1, 2 or 3>]
[-am <0, 1 or 2] [-sm 1 or 2] [-od olddomainfqdn] [-nd newdomainfqdn]
-ad: Retrieve the new SMTP address from active directory.
-dc: Name of the Domain Controller to connect to. RootDSE used by default.
-t: AD timeout in seconds. Default value is 120 seconds.
-od: The FQDN of the old domain. For example: contoso.com.
-nd: The FQDN of the new domain. For example: northwindtraders.com.
-pm: Profile mode: 1 = default, 2 = all, 3 = specific.
-pn: Name of the profile to process. For example: "Outlook". The default profile will be used if no profile name is specified.
-am: Account mode: 1 = default, 2 = all.
-sm: Store mode: 1 = default, 2 = all.
-?: Displays this usage information.
- Use AD to retrieve the primary SMTP address. Connect to CONTOSO_DC_01 and set the timeout to 180 seconds:
ProfileAccountUpdateTool -ad -dc CONTOSO_DC_01 -t 180
- Specify the old and new SMTP domains and skip AD lookup:
ProfileAccountUpdateTool -od contoso.com -nd talespintoys.com
- Specify the old and new SMTP domains and skip AD lookup. Update all profiles, stores and accounts:
ProfileAccountUpdateTool -od contoso.com -nd talespintoys.com -pm 2 -sm 2 -am 2
- 23/05/2017: Made a few changes to the AD connection code to get rid of unnecessary logic.
- 03/02/2016: Added code to allow changing the domain name only without having to connect to Active directory and code for narrowing down the processing to the default profile/account/store or just the default ones.