How to Automatically Renew OAuth Token for Extended MAPI Applications Using Outlook

Adrian Drollinger 0 Reputation points
2025-01-09T09:49:45.8333333+00:00

The article

https://learn.microsoft.com/en-us/outlook/troubleshoot/authentication/expose-permissions-issue-with-mapi-oauth-tokens?source=docs

suggests establishing an initial connection with Outlook and then using the same Outlook profile with an Extended MAPI application to connect to a mailbox.

This approach works only for 24 hours; after that, the OAuth token appears to expire and requires renewal by running Outlook interactively.

My Extended MAPI application is running as a Windows Service and connects to a M365 mailbox at regular intervals. It utilizes the preconfigured Outlook profile as described in the article but fails to connect after 24 hours. When Outlook is run interactively before the 24-hour mark, the connection continues to work, but it fails if Outlook is not run again.

How can Outlook be started and exited from a Windows service (potentially using a startup switch) to renew the Outlook token before it expires after 24 hours? Previous attempts to run Outlook and terminate the process after a couple of minutes have not been successful.

Alternatively, is there an API call available from Extended MAPI that replicates the token renewal functionality of Outlook? Why is there a lack of documentation or sample code regarding this?

Previous Outlook versions (up to and including V2403, Build 17425.20146 from March 29, 2024) did not require running Outlook daily to maintain the Extended MAPI application. What has changed in the newer Outlook versions, and how can this issue be resolved?

Outlook
Outlook
A family of Microsoft email and calendar products.
4,291 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,141 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.