Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/islandboymv/m365-graph-mailer/archive/refs/heads/main.zipSends all WordPress and WooCommerce mail through the Microsoft Graph API using application-only authentication.
The site authenticates as a registered Entra application, not as a person. No mailbox password is stored anywhere, and delivery is unaffected when someone changes their password or leaves the organisation — the failure mode that makes delegated OAuth a poor fit for transactional email.
Why not WP Mail SMTP's Outlook mailer
It only implements the delegated flow: it signs a user in and calls
/me/sendMail. That requires the mailbox owner's credentials, and the resulting refresh
token dies with their password. This plugin calls /users/{mailbox}/sendMail with an
application token instead.
SMTP AUTH is not an alternative here — it is disabled org-wide on this tenant, and Microsoft disables Basic auth for client submission by default from the end of December 2026.
Setup
1. Entra ID — register the application
- App registrations → New registration. Name it, single tenant, no redirect URI (there is no browser flow).
- API permissions → Add → Microsoft Graph → Application permissions →
Mail.Send. It must be Application, not Delegated. - Grant admin consent.
- Certificates & secrets → New client secret. Copy the Value immediately; it is only shown once.
2. Exchange — fence the app to one mailbox
Mail.Send as an application permission is tenant-wide: without this step the credential
could send as anyone in the organisation.
pwsh -File setup/Set-GraphMailerPolicy.ps1 -AppId <application-id> # preview
pwsh -File setup/Set-GraphMailerPolicy.ps1 -AppId <application-id> -Apply # create
It verifies afterwards that the app is Granted on the shop mailbox and Denied on
another one. Policy changes can take up to 30 minutes to propagate.
3. WordPress — credentials
Preferred, in wp-config.php, so the secret stays out of the database and out of any
database export:
define( 'MGM_TENANT_ID', '...' );
define( 'MGM_CLIENT_ID', '...' );
define( 'MGM_CLIENT_SECRET', '...' );
define( 'MGM_FROM_ADDRESS', 'shop@example.com' );
Anything not defined as a constant can be entered at Settings → Graph Mailer, which also has a test-send button and the log. Constants win and are shown locked.
Disable any other mailer plugin first. Two plugins competing for wp_mail() is a
confusing way to lose email.
Behaviour
- Hooks
pre_wp_mail. If credentials are missing it returnsnulland WordPress falls back to its default mailer rather than silently dropping the message. - Access tokens are cached in a transient and renewed a minute before expiry. A
401clears the cache so a rotated secret recovers on the next send. - Handles HTML and plain text, Cc, Bcc, Reply-To, and
Name <addr@example.com>forms. - Attachments up to 3 MB (the Graph limit for simple attachments). Larger ones are skipped and logged rather than failing the whole message.
- Every attempt is recorded; the last 200 are kept. An admin notice appears if anything failed in the previous 24 hours.
- Messages are not copied to the mailbox's Sent Items by default — the shop mailbox
is read by a human and order mail would bury their own. Enable with
define( 'MGM_SAVE_TO_SENT', true );.
Filters
| Filter | Purpose |
|---|---|
mgm_graph_message |
Alter the Graph message resource before sending. |
mgm_save_to_sent_items |
Toggle the Sent Items copy per message. |
mgm_send_failed |
Action fired with the WP_Error when a send fails. |
Troubleshooting
| Symptom | Cause |
|---|---|
ErrorAccessDenied on send |
Application Access Policy has not propagated, or scopes the wrong mailbox. |
MailboxNotEnabledForRESTAPI |
The from address has no Exchange mailbox. |
invalid_client on the token request |
Secret expired or was rotated without updating wp-config.php. |
| Mail sends but lands in spam | Check that DKIM is enabled for the sending domain in Microsoft 365. |