Skip to content
You're viewing documentation for v3.0.1. It may be out of date.Go to latest
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Microsoft Graph

Send through Microsoft Graph's sendMail API with OAuth 2.0 client credentials or custom token providers for managed identity and certificate authentication.

Capabilities

Repeated headers Idempotency Scheduling Personalized
Yes none No expanded

These values come from the adapter’s exported capabilities declaration. The field support matrix covers normalized message fields.

The Graph adapter calls Microsoft Graph’s sendMail API with plain fetch and supports both OAuth 2.0 client credentials flow and custom getAccessToken functions for managed identity, certificate-based authentication, or external token providers. It authenticates with app permissions (Mail.Send) and sends from a specific user’s mailbox by user ID or UPN.

SMTP
Microsoft GraphLive check available@opencoredev/email-sdk/graph
Provider docs

Configure

Create an app registration in Microsoft Entra ID (Azure AD), grant it the Mail.Send application permission, get admin consent, and verify the sender identity matches a real mailbox in your tenant.

PropType
tenantId?string

Microsoft Entra tenant ID. Required unless using getAccessToken.

Typestring
clientId?string

Application (client) ID from your app registration. Required unless using getAccessToken.

Typestring
clientSecret?string

Client secret value from your app registration. Required unless using getAccessToken.

Typestring
userstring

User ID (GUID) or UPN (email) of the mailbox to send from, e.g. d4f540b2-6478-4ee3-bdd3-d3a5397d97ac or john.doe@contoso.com.

Typestring
getAccessToken?() => string | Promise<string>

Custom token provider for managed identity, certificate credentials, or external caching. Skips the built-in client credentials flow. Mutually exclusive with tenantId/clientId/clientSecret.

Type() => string | Promise<string>
baseUrl?string

Override the Graph API origin for national clouds.

Typestring
Default"https://graph.microsoft.com/v1.0"
tokenUrl?string

Override the OAuth token endpoint.

Typestring
Default"https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token"
scope?string

OAuth scope for client credentials. For national clouds, use the Graph service origin followed by /.default.

Typestring
Default"https://graph.microsoft.com/.default"
tokenTimeoutMs?number

Maximum time to wait for the built-in client-credentials token request, including its response body.

Typenumber
Default30000
saveToSentItems?boolean

Store a copy in the sender's Sent Items folder.

Typeboolean
Defaulttrue
fetch?typeof fetch

Custom fetch implementation for tests or special runtimes.

Typetypeof fetch

Send

Graph maps cc, bcc, one replyTo, custom headers (x- prefix only), and base64 attachments. There are no tags, metadata, or scheduled delivery.

Graph returns a 202 Accepted status with an empty body, so there is no message ID. If you need to correlate delivery events later, keep saveToSentItems enabled and retrieve the internetMessageId from the Sent Items copy.

Managed identity and certificate authentication

Pass a custom getAccessToken function to skip the built-in client credentials flow. The adapter calls your function before every send and caches nothing, so you control token lifetime and refresh logic.

When getAccessToken is supplied, tenantId, clientId, and clientSecret must not be set.

Verify from the CLI

Export MS_GRAPH_CLIENT_SECRET in your shell or inject it through your secret manager. The CLI reads it from the environment; do not pass it as a command-line argument.

Drop --dry-run for one real send. Only Microsoft can prove the app registration, consent, and mailbox are set up correctly.

National clouds and Convex

Add --live to doctor --adapter graph for a non-sending client-credentials check. It verifies authentication, not mailbox access, Mail.Send consent, or delivery. The CLI accepts --token-url / MS_GRAPH_TOKEN_URL and --scope / MS_GRAPH_SCOPE for national-cloud authentication, alongside --base-url / MS_GRAPH_BASE_URL for sending.

For a national-cloud SDK client, configure baseUrl, tokenUrl, and scope together. For example, US Government L4 uses https://graph.microsoft.us/v1.0, https://login.microsoftonline.us/<tenant-id>/oauth2/v2.0/token, and https://graph.microsoft.us/.default. See Microsoft’s national-cloud guidance.

In the Convex component, endpoint overrides and scope are server-controlled through MS_GRAPH_BASE_URL, MS_GRAPH_TOKEN_URL, and MS_GRAPH_SCOPE. Public send requests cannot provide literal endpoint URLs, so callers cannot redirect server credentials. MS_GRAPH_CLIENT_SECRET is restricted to Graph’s clientSecret field; other adapter or field environment overrides cannot read it. Graph’s environment mappings are fixed to its declared variables. Map custom secret names in the trusted app.use(convexEmail, { env }) configuration, not in send requests.

Last updated on