Skip to content

Add a Microsoft 365 (OAuth) mail transport - #101

Merged
robgietema merged 3 commits into
mainfrom
feature/mail-oauth-microsoft365
Nov 7, 2026
Merged

robgietema merged 3 commits into
mainfrom
feature/mail-oauth-microsoft365

Conversation

@robgietema

Copy link
Copy Markdown
Member

Summary

Nick can now send mail through Microsoft 365 using OAuth, as an alternative to SMTP with a user name and password.

  • The mail control panel gets a Mail transport choice (SMTP or Microsoft 365 (OAuth)) and a Microsoft 365 (OAuth) tab with the Application (client) ID, Tenant ID and Client secret. The secret uses the password widget, so it is never returned and an empty value keeps the stored one.
  • With the Microsoft 365 transport, Nick gets an app-only token from Entra ID (client credentials flow, scope https://graph.microsoft.com/.default), caches it in memory until a minute before it expires, and sends the message through the Microsoft Graph sendMail endpoint for the site "From" address.
  • The message is built by nodemailer (stream transport) and sent to Graph as MIME, so HTML, attachments and Bcc work and every caller of sendMail() is unchanged.
  • SMTP stays the default and debug mode still uses the Ethereal test server.
  • Upgrade 1019 adds the new fields to existing sites and sets the transport to SMTP, so nothing changes until an admin switches. Run pnpm seed:upgrade.
  • New admin guide page docs/admin-guide/mail.md with the Azure setup (app registration, Mail.Send application permission with admin consent, client secret, optional application access policy).

Only Microsoft 365 is supported. Graph was chosen over SMTP XOAUTH2 because it only needs the Mail.Send application permission, while XOAUTH2 also needs the app registered in Exchange Online and SMTP AUTH enabled on the mailbox.

Commits

  1. The transport, control panel, upgrade, tests, docs and changelog.
  2. The new strings in the locales, generated with pnpm i18n (they are untranslated).

Checks

  • 8 new tests in src/helpers/mail/mail.test.ts with fetch mocked: token request and Graph request shape, token reuse, refresh near expiry, authentication and send errors, missing settings, and the SMTP path. Mail and controlpanels tests pass (33), typecheck and lint pass.
  • Comparing every language .json before and after pnpm i18n: no translation lost.
  • Not tested against a real tenant. A real send needs Azure credentials, so that still has to be tried by hand.

Send mail through the Microsoft Graph API using the client credentials flow.
The mail control panel gets a transport choice and the application (client) ID,
tenant ID and client secret. Upgrade 1019 adds the fields to existing sites.
@robgietema
robgietema merged commit b07e62f into main Nov 7, 2026
10 checks passed
@robgietema
robgietema deleted the feature/mail-oauth-microsoft365 branch November 7, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant