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

Adrian Drollinger 0 Reputation points
2026-01-13T14:52:29.1966667+00:00

When you interactively open Outlook it renews the access tokens automatically in the background. How can an Extended MAPI application do this automatically in the background when it runs as a service?

I have an Outlook MAPI application that runs as a Windows service and accesses mailboxes using a pre-configured Outlook profile.

The application works until the M365 access tokens expire. If I manually open Outlook before the tokens expire, the MAPI application continues to run; if I don't, the application can't access the mailboxes anymore.

Can Outlook be started with a command-line switch from a Windows service to renew the tokens, or is there an API- command that can be executed?

Microsoft 365 and Office | Development | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2026-01-13T14:52:39.4733333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To automatically renew OAuth tokens for Extended MAPI applications using Outlook, the recommended approach is to establish an initial connection using the Outlook client. Once this connection is made, Outlook will manage the OAuth tokens in the background, allowing your Extended MAPI application to reuse these tokens without requiring manual intervention.

    Unfortunately, there is no direct command-line switch or API command that can be executed from a Windows service to automatically renew the tokens without opening the Outlook client interactively. The application must rely on the Outlook profile to acquire the necessary OAuth tokens, which can only be done through the Outlook client itself.

    If your application requires continuous access, you may consider implementing a mechanism that checks the token status and prompts the user to open Outlook if the tokens are about to expire, ensuring that the MAPI application can continue to function seamlessly.


    References:

    0 comments No comments

  2. TiNo-T 10,660 Reputation points Microsoft External Staff Moderator
    2026-01-14T01:25:50.9433333+00:00

    Dear @Adrian Drollinger,

    Thank you for your detailed explanation of the issue. I understand how frustrating it can be when your Extended MAPI application suddenly stops accessing the mailbox after the OAuth token expires. I truly appreciate the time you've spent investigating this.

    Based on my research, this behavior is expected due to how Outlook and Extended MAPI handle Modern Authentication. Microsoft explains this clearly in their official documentation (the Q&A Assist also mentioned it):

    Reference: Microsoft doesn't expose permissions to generate OAuth tokens for Extended MAPI access to mailboxes

    According to this article, Microsoft does not expose a permissions model that allows Extended MAPI applications to generate or renew OAuth tokens directly. Only Outlook itself can obtain and refresh these tokens. Because of this limitation, if Outlook is not opened interactively by a user, the token eventually expires and the Extended MAPI application can no longer authenticate.

    This means for your scenario:

    • Outlook automatically renews the token only when it is opened interactively.
    • A Windows Service or background process cannot trigger token renewal on its own.
    • When the token expires, the Extended MAPI application fails until Outlook is opened once again.

    This aligns exactly with the issues you are encountering.

    Also, the article above provides the only supported workaround:

    User's image

    • Open Outlook interactively at least once to allow it to acquire fresh OAuth tokens.
    • After Outlook refreshes the token, the Extended MAPI application can reuse it and continue to function normally.
    • Unfortunately, there is no API, command-line switch, or background method that forces Outlook to renew OAuth tokens without user interaction.

    So, if possible:

    • Ensure Outlook is opened interactively by the user at least once during the token lifetime, so it can refresh the token automatically.
    • Consider evaluating alternative APIs (EWS with OAuth or Microsoft Graph) if your application needs stable, unattended, server-side access. These APIs fully support Modern Authentication without requiring Outlook to run (please kindly check this information in that article as well).

    I hope this information can give you more insights in this case. Wish you a pleasant day!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


Your answer

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