Repository navigation
Send email through Microsoft 365 with EMAIL_DRIVER=graph - #75
thomassicaud wants to merge 3 commits into
Conversation
|
@thomassicaud-asi is attempting to deploy a commit to the Basic Intelligence Team on Vercel. A member of the Team first needs to authorize it. |
[High impact] The PR appears safe to merge, with the earlier non-blocking readiness-display issue still open. Findings
SummaryAdds Microsoft 365 email sending with
The token-cache and token-refresh findings are fixed. No new findings were accepted.
|
| ready: resolvedSettings.emailReadyAt !== null, | ||
| senderAddress: graph.sender, | ||
| state: "graph", |
There was a problem hiding this comment.
Old checks mark Graph ready. Switching an existing install from Resend to Graph keeps its saved
emailReadyAt. This branch then reports “Email is working” before any Graph test succeeds, even when the new app cannot use the mailbox. Tie the saved check to the active provider and mailbox so switching providers asks for a new test.
Organizations whose mail already lives in Microsoft 365 can send from one
of their own mailboxes through Microsoft Graph instead of bringing in
Resend. The app signs in with OAuth client credentials and calls
POST /users/{mailbox}/sendMail, with no new dependency.
- New driver in src/lib/services/email-graph.ts: token cache, retries on
429/503 within the same bounds as Resend, one token refresh on 401, and
Microsoft's own error words passed through to the test email.
- MICROSOFT_GRAPH_SENDER fixes the sender, like RESEND_FROM_EMAIL does;
Settings names whichever variable is in use.
- Settings, Organization shows a Microsoft 365 status instead of the
Resend domain steps, and asks for a test email to confirm the mailbox.
- Attachments above about 3 MB go out as links, since Graph takes at most
4 MB per message.
- docs/self-hosting.md explains how to scope the app to that one mailbox
with Exchange RBAC for Applications.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a9a898f to
5367a06
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses two review notes on NYLLON-SOFTWARE#75: - One Graph sender per configuration for the whole process, so the token is reused by every email service instead of fetched again for each envelope. A rotated secret or another mailbox gets a sender of its own. - A 401 that follows a throttled try now still replaces the token once: token refresh and throttling retries are counted apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged The settings flow from #76 is up as #254, on top of this one. |
What and why
Organizations whose mail already lives in Microsoft 365 can now send SignuDoc's email from one of their own mailboxes through Microsoft Graph, instead of signing up for Resend and verifying a domain there. We run SignuDoc for our contracts and our mail is in Exchange Online; adding a second mail provider for one app was the main thing in the way.
src/lib/services/email-graph.ts: the app signs in with OAuth client credentials and callsPOST /users/{mailbox}/sendMail. No new dependency (plainfetch). The token is cached until a minute before it expires; a 429/503 is retried afterRetry-Afterwithin the same bounds as the Resend driver (3 tries, at most 5 s each); a 401 gets one fresh token. Microsoft's own error words reach the test email (for exampleErrorAccessDenied: ..., or theAADSTS…line without its trace ids).MICROSOFT_GRAPH_SENDERfixes the sender the wayRESEND_FROM_EMAILdoes. Settings now names whichever variable is in use (senderAddressVariable) instead of always sayingRESEND_FROM_EMAIL.fitsAsAttachmentsnow depends on the driver: above about 2.9 MB the signed copy goes out as links, as it already does above Resend's limit.docs/self-hosting.mdhas a "Send email through Microsoft 365" section. It insists on scoping the app to that one mailbox with Exchange RBAC for Applications, because Mail.Send granted in Entra lets an app send as anyone in the tenant.The shape follows #51 (Cloudflare email): one
email-<provider>.tsmodule, one moreEMAIL_DRIVERvalue, one more status inemail-status.ts. Whichever lands first, the other is a small rebase, and I'm happy to do it.Not in this PR
Testing
npm test: 311 pass, including 15 new tests inemail-graph.test.ts(payload, token reuse and renewal, 401 refresh, throttling, error messages, batch, attachment limit). Nothing talks to Microsoft:fetchis injected.npm run typecheck,npm run lint(no new warnings) andprettier --checkon the changed files.403 ErrorAccessDeniedon any other.🤖 Generated with Claude Code
Note
Add Microsoft 365 Graph email driver with
EMAIL_DRIVER=graphRetry-Afterwait. See email-graph.ts.MICROSOFT_GRAPH_TENANT_ID,MICROSOFT_GRAPH_CLIENT_ID,MICROSOFT_GRAPH_CLIENT_SECRET, andMICROSOFT_GRAPH_SENDER. All send from one shared mailbox and save to its Sent Items.senderAddressVariablein env.ts, and the settings panel shows Graph status, missing variables, and the sender mailbox in organization-settings.tsx.GRAPH_MAX_ATTACHMENT_BYTES) than Resend, and senders are shared process-wide per configuration hash.Macroscope summarized 1a24f15.