momenoor/laravel-msgraph-mailer
Composer 安装命令:
composer require momenoor/laravel-msgraph-mailer
包简介
Laravel mail transport driver for sending emails via Microsoft Graph API with OAuth2 authentication
README 文档
README
A Laravel mail transport driver for sending emails via Microsoft Graph API using OAuth2 authentication.
This package provides a custom Symfony Mailer transport that integrates seamlessly with Laravel's mail system, allowing you to send emails through Microsoft 365 (formerly Office 365) using the Microsoft Graph API with application permissions (client credentials flow).
Installation
You can install the package via composer:
composer require maize-tech/laravel-msgraph-mailer
Configuration
Add the Microsoft Graph mailer configuration to your config/mail.php file:
'mailers' => [ // ... other mailers 'microsoft-graph' => [ 'transport' => 'microsoft-graph', 'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'), 'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'), 'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'), ], ],
Add the required environment variables to your .env file:
MAIL_MAILER=microsoft-graph MICROSOFT_GRAPH_TENANT_ID=your-tenant-id MICROSOFT_GRAPH_CLIENT_ID=your-client-id MICROSOFT_GRAPH_CLIENT_SECRET=your-client-secret
Usage
Once configured, you can use Laravel's Mail facade as usual. The package will automatically handle OAuth2 authentication and send emails via Microsoft Graph API.
Basic Email
use Illuminate\Support\Facades\Mail; Mail::raw('Hello from Microsoft Graph!', function ($message) { $message->to('recipient@example.com') ->subject('Test Email'); });
Using Mailables
use Illuminate\Support\Facades\Mail; use App\Mail\WelcomeEmail; Mail::to('user@example.com')->send(new WelcomeEmail($user));
HTML Emails with Attachments
use Illuminate\Support\Facades\Mail; Mail::send('emails.welcome', ['user' => $user], function ($message) use ($user) { $message->to($user->email) ->subject('Welcome!') ->attach('/path/to/file.pdf'); });
Token Caching Issues
Access tokens are cached for 55 minutes by default. If you need to clear the cache:
app('mail.microsoft-graph.token-provider')->clearToken();
Features
- OAuth2 Authentication: Uses client credentials flow for secure authentication
- Automatic Token Caching: Access tokens are cached for 55 minutes
- Retry Logic: Automatic retry on transient failures with attempts and delays
- Full Email Support:
- HTML and plain text emails
- File attachments (including inline images)
- Multiple recipients (To, CC, BCC)
- Reply-To headers
- Laravel Integration: Works seamlessly with Laravel's Mail facade, Mailables, and Notifications
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
momenoor/laravel-msgraph-mailer 适用场景与选型建议
momenoor/laravel-msgraph-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「oauth2」 「email」 「azure」 「laravel」 「transport」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 momenoor/laravel-msgraph-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 momenoor/laravel-msgraph-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 momenoor/laravel-msgraph-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Email Toolkit Plugin for CakePHP
Mail libraries used by Zimbra Api
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-08