Email: Register a Microsoft app
Register your own Microsoft app for Outlook.com and Microsoft 365 sign-in, with the redirect and permissions Mail needs.
Outlook.com and Microsoft 365 take only OAuth for IMAP and SMTP, so mail signs in through a Microsoft app. This page
is for whoever registers that app: WireCat once for everyone, or you for yourself. It takes about half an hour, and it
costs nothing.
When the app exists, its Application (client) ID goes either into mail itself (WireCat's app), or into your
config once, with your app's id in place of the example id:
mail config set --defaults microsoft_client_id 11111111-2222-3333-4444-555555555555Only you can set it, in a terminal: an agent over MCP is refused, as for the mail server settings. The id is public; a desktop app has no secret.
What you need
- A Microsoft account that can create apps in a Microsoft Entra tenant. A work or school account usually can. A personal Outlook.com account has no tenant of its own: sign up for a free Azure account first, which makes one (register an app, prerequisites).
- A personal Outlook.com mailbox, to test the app at the end.
Steps
-
Open the Microsoft Entra admin center and sign in.
-
Open App registrations (type it in the search box at the top), and select New registration.
-
Fill in the form:
- Name:
WireCat mail(users see it on the consent page). - Supported account types: Any Entra ID Tenant + Personal Microsoft accounts. Without the personal accounts, Outlook.com users cannot sign in.
- Redirect URI: leave it empty here; step 6 adds it.
- Name:
-
Select Register. The app's Overview page opens. Copy the Application (client) ID: that is the id
mailneeds. -
Allow the desktop sign-in: under Manage, select Authentication. Under Advanced settings, set Allow public client flows to Yes, and select Save.
-
Add the redirect URI. Under Manage, select Authentication, then Add a platform, then Mobile and desktop applications. In Custom redirect URIs enter
http://localhost/callback, with no port, and select Configure.mailsigns in throughhttp://localhost:<port>/callbackwith a new port each time; Microsoft ignores the port only forlocalhostaddresses and requires the path to match (redirect URI rules). No manifest edit is needed. Do not put the address under a Web platform: that kind of app expects a client secret, and a public client sign-in with it fails. If the address is already listed under Web, remove it there. -
List the permissions, so the consent page and admins see them up front. The sign-in asks for them by name anyway (scopes), so this step is recommended, not required. Microsoft's page gives no portal steps for these delegated permissions; they are usually under Manage, API permissions, Add a permission, Microsoft Graph, Delegated permissions (if not, APIs my organization uses, Office 365 Exchange Online). Tick:
IMAP.AccessAsUser.AllSMTP.Sendoffline_access
Select Add permissions. Do not grant admin consent for these: each person allows them for their own mailbox when they sign in. Microsoft lets users do that by default for their own mail (user consent).
-
Test the redirect. Put the id into your config as above, then sign in twice. The id and the address below are examples: use your app's Application (client) ID and your own address.
mail config set --defaults microsoft_client_id 11111111-2222-3333-4444-555555555555 mail outlook-test session start --address [email protected] mail outlook-test session startBoth must end with
signed_in: true. If Microsoft's page shows an error withAADSTS50011(the redirect URI does not match), check that the address under Mobile and desktop applications is exactlyhttp://localhost/callback. -
For WireCat's own app: send the Application (client) ID to the maintainers. A later release of
mailthen signs in with it without any config.
Later, and not needed to start
- A shared app for a whole organisation. Making a shared Microsoft app public is complex, so an admin who restricts consent may refuse WireCat's app. The admin approves it, or registers the organisation's own app with these steps and gives you its id.
- Sending from Microsoft 365 needs "Authenticated SMTP" on for the mailbox. Security defaults, and organisations created after January 2020, turn it off; an admin turns it on per mailbox (SMTP AUTH). Reading works either way.
What the sign-in asks for
| Scope | What mail does with it |
|---|---|
https://outlook.office.com/IMAP.AccessAsUser.All | read and change the mail over IMAP |
https://outlook.office.com/SMTP.Send | send mail as the account over SMTP |
offline_access | a refresh token, so a scheduled sync needs no new sign-in |
The tokens stay in the system keyring of the computer that signed in, as the app passwords do. mail <profile> session end forgets them; Microsoft keeps listing the app until you remove it at
https://www.microsoft.com/consent (personal account) or https://myapps.microsoft.com (work or school).