Msgraph is a new package made with Moox.
The package provides Microsoft Graph SDK client creation for moox packages, including:
- a named connection registry (tenant + app credentials resolved by name)
- a Graph client factory
- an immutable-identifier header middleware on every outgoing request
- a Graph
InboxDriver(Moox\MsGraph\Mail\GraphInboxDriver) auto-registered asmsgraphonInboxDriverManagerwhenmoox/mail-inboxis installed - a Graph outbound mail transport (
microsoftgraphdriver) registered with Laravel'sMail::extend, plus a defaultmsgraphmailer — both built from the same connection registry
- Named connection registry (
Auth\ConnectionRegistry) resolving credentials by connection name Auth\GraphClientFactorybuilding authenticatedGraphServiceClientinstances for named connections- Every outgoing request carries
Prefer: IdType="ImmutableId"(immutable identifiers) - Typed exception types for Graph API failures (authentication, rate limiting, not found, connection/transport, expired delta sync state)
- Graph inbox driver: resumable delta fetch, claim, settle-by-outcome, attachment download
- Graph outbound mail transport: Symfony mailer bridge (
symfony/microsoft-graph-mailer) registered as themicrosoftgraphdriver, with a defaultmsgraphmailer that a host app can override - This package owns mailbox folder names; consumers pass settlement outcomes only
- Configuration-only package: no models, no migrations, and no Filament surface
To install this package, require it via Composer and run the Moox Installer:
composer require moox/msgraph
php artisan moox:installLearn more about the Moox Installer or common requirements.
moox/mail-inbox is optional. Install it only if you use the Graph inbox driver (Exchange Online mailboxes). Sending mail through the microsoftgraph transport (and the default msgraph mailer) works without it.
Publish the config:
php artisan vendor:publish --tag=msgraph-configSet your Azure AD credentials in .env (the default connection):
MSGRAPH_TENANT_ID=your-tenant-id
MSGRAPH_CLIENT_ID=your-client-id
MSGRAPH_CLIENT_SECRET=your-client-secretFor multiple connections, add entries to config/msgraph.php:
'connections' => [
'default' => [
'tenant_id' => env('MSGRAPH_TENANT_ID'),
'client_id' => env('MSGRAPH_CLIENT_ID'),
'client_secret' => env('MSGRAPH_CLIENT_SECRET'),
],
'secondary' => [
'tenant_id' => env('MSGRAPH_SECONDARY_TENANT_ID'),
'client_id' => env('MSGRAPH_SECONDARY_CLIENT_ID'),
'client_secret' => env('MSGRAPH_SECONDARY_CLIENT_SECRET'),
],
],Register an Azure AD App Registration with application permissions (not delegated):
Mail.Read/Mail.ReadWrite— for mail operationsUser.Read.All— for user lookups
Grant admin consent after adding the permissions.
use Moox\MsGraph\Auth\GraphClientFactory;
$factory = app(GraphClientFactory::class);
// Default connection
$client = $factory->make();
// Named connection
$client = $factory->make('secondary');Moox\MsGraph\Mail\GraphInboxDriver implements Moox\MailInbox\Contracts\InboxDriver. The service provider registers it as the msgraph driver on InboxDriverManager when that manager is bound. Construct it manually with a GraphServiceClient from GraphClientFactory, a mailbox address, and MailSettings if you need a one-off instance. Expired delta tokens surface as Moox\MailInbox\Exceptions\InvalidSyncCursorException.
Folder display names and $top (page_size) live only in config/msgraph.php. The per-run page budget (mail-inbox.delta_max_pages_per_poll) is enforced by moox/mail-inbox. Domain code passes a SettlementOutcome (Processed, Failed, Ignored); it never passes a folder name. Consumers such as moox/e-billing settle foreign invoices as Ignored — they do not define EBILLING_IGNORED_FOLDER or other mailbox folder settings locally.
MSGRAPH_MAIL_PROCESSING_FOLDER=Processing
MSGRAPH_MAIL_PROCESSED_FOLDER=Processed
MSGRAPH_MAIL_FAILED_FOLDER=Failed
MSGRAPH_MAIL_IGNORED_FOLDER=Ignored
MSGRAPH_MAIL_PAGE_SIZE=50'mail' => [
'folders' => [
'processing' => env('MSGRAPH_MAIL_PROCESSING_FOLDER', 'Processing'),
'processed' => env('MSGRAPH_MAIL_PROCESSED_FOLDER', 'Processed'),
'failed' => env('MSGRAPH_MAIL_FAILED_FOLDER', 'Failed'),
'ignored' => env('MSGRAPH_MAIL_IGNORED_FOLDER', 'Ignored'),
],
'page_size' => (int) env('MSGRAPH_MAIL_PAGE_SIZE', 50),
],An empty processing folder skips the claim move (and creates nothing). Outcome mapping:
| Call | Config key | Default folder |
|---|---|---|
claim() |
msgraph.mail.folders.processing |
Processing |
settle(Processed) |
msgraph.mail.folders.processed |
Processed |
settle(Failed) |
msgraph.mail.folders.failed |
Failed |
settle(Ignored) |
msgraph.mail.folders.ignored |
Ignored |
settle(Processed) marks the message as read in Graph before moving it to the processed folder (same behaviour as the pre-extraction pipeline finalizer).
Folders are resolved by display name and created when missing. fetch() returns one Graph delta page. When Graph returns @odata.nextLink, that value is MessagePage::$continuationCursor so the domain job can loop up to mail-inbox.delta_max_pages_per_poll. When Graph returns @odata.deltaLink, that value is MessagePage::$resumeCursor (persist for the next poll). Both tokens are opaque; this driver allowlists Graph national-cloud hosts before calling withUrl(). Every request carries Prefer: IdType="ImmutableId".
The service provider registers a Symfony mailer transport under the microsoftgraph driver via Mail::extend. The transport is the Symfony bridge symfony/microsoft-graph-mailer (app-only client-credentials flow). The DSN is built from the same connection registry used by the inbox driver, so tenant credentials live only in config/msgraph.php — there is no separate mailer DSN env var:
microsoftgraph+api://<clientId>:<clientSecret>@default?tenantId=<tenantId>
An explicit Symfony HttpClient is passed to MicrosoftGraphTransportFactory, since the factory does not create one on its own.
The registered transport wraps the Symfony bridge in GraphHeaderSanitizingTransport, which removes headers Graph cannot accept as custom internetMessageHeaders (only names starting with x- / X- are allowed). This includes caller-supplied Message-ID values from upstream mail code.
Unless the host app has already defined mail.mailers.msgraph, the provider also registers a default named mailer:
'msgraph' => [
'transport' => 'microsoftgraph',
'connection' => config('msgraph.default', 'default'),
],The connection key selects which named connection from config/msgraph.php supplies the credentials. By default, sent mail is copied to the mailbox's Sent Items folder (a provable sent copy).
Prerequisites to send:
- The Azure AD app registration needs the Mail.Send application permission with admin consent
- An Application Access Policy must scope which mailbox(es) the app may send as
- The sender address (
mail.from.address/MAIL_FROM_ADDRESS) must be a real, licensed mailbox in the tenant
Please see CHANGELOG for more information on what has changed recently.
Please review our security policy on how to report security vulnerabilities.
Thanks to so many people for their contributions to Moox, special thanks to our sponsors.
Want to help us to develop and grow Moox. Fortunately there are so many ways to do this, learn more about helping Moox.
The MIT License (MIT). Please see our license and copyright information for more information.

