victord11/laravel-msgraph-mail
Composer 安装命令:
composer require victord11/laravel-msgraph-mail
包简介
Laravel Mail driver for Microsoft Office 365 using the MSGraph API
README 文档
README
This package provides a Microsoft Graph mail driver for Laravel. It is an alternative when you don't want to use the deprecated and unsecure Basic Auth SMTP driver with Microsoft Office 365.
This package it's a fork of the InnoGE/laravel-msgraph-mail package, which is no implemented password grant authentication. It has been improved to support both Client Credentials and Resource Owner Password Credentials authentication methods.
Installation
You can install the package via composer:
composer require victord11/laravel-msgraph-mail
Configuration
Register the Azure App
Microsoft Azure AD Configuration
I have written a detailed Blog Post how you can configure your Microsoft Azure AD Tenant. Sending Mails with Laravel and Microsoft Office 365 the secure way
I want to figure it out on my own
You need to register an Azure App in your Azure AD tenant. You can do this by following the steps in the Microsoft Graph documentation.
After creating the App you have to add the following permissions to the App: Mail.Send (Application permission) you will find it under the "Microsoft Graph" section.
Now you have to Grant Admin Consent for the App. You can do this by following the steps in the Microsoft Graph documentation.
Configuring your Laravel app
First you need to add a new entry to the mail drivers array in your config/mail.php configuration file:
Client Credentials Authentication (Default)
'microsoft-graph' => [ 'transport' => 'microsoft-graph', 'auth_method' => 'client_credentials', 'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'), 'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'), 'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'), 'from' => [ 'address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME'), ], 'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false), ],
Resource Owner Password Credentials Authentication
'microsoft-graph' => [ 'transport' => 'microsoft-graph', 'auth_method' => 'password', 'client_id' => env('MICROSOFT_GRAPH_CLIENT_ID'), 'client_secret' => env('MICROSOFT_GRAPH_CLIENT_SECRET'), 'tenant_id' => env('MICROSOFT_GRAPH_TENANT_ID'), 'username' => env('MICROSOFT_GRAPH_USERNAME'), 'password' => env('MICROSOFT_GRAPH_PASSWORD'), 'from' => [ 'address' => env('MAIL_FROM_ADDRESS'), 'name' => env('MAIL_FROM_NAME'), ], 'save_to_sent_items' => env('MAIL_SAVE_TO_SENT_ITEMS', false), ],
For the client_id, client_secret and tenant_id you need to use the values from the Azure App you created in the
previous step.
Note: The client_credentials method is recommended for production use as it's more secure. The password method should only be used when necessary and in secure environments.
The save_to_sent_items option in Microsoft Graph refers to a parameter that determines whether a sent email should be saved to the sender's "Sent Items" folder within their mailbox. When this option is set to true, the email will be automatically saved to the "Sent Items" folder, providing a record of the communication. Conversely, when it's set to false, the email will not be saved to the "Sent Items" folder.
By default, the save_to_sent_items option is set to false, which means that emails sent through Microsoft Graph won't be saved in the sender's "Sent Items" folder unless explicitly specified otherwise. This behavior can be useful in scenarios where you might want more control over which emails are saved as sent items, perhaps to reduce clutter or ensure confidentiality.
Now you can switch your default mail driver to the new microsoft-graph driver by setting the env variable:
MAIL_MAILER=microsoft-graph
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.
victord11/laravel-msgraph-mail 适用场景与选型建议
victord11/laravel-msgraph-mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「microsoft」 「victord11」 「innoge」 「laravel-msgraph-mail」 「microsoft-graph」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 victord11/laravel-msgraph-mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 victord11/laravel-msgraph-mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 victord11/laravel-msgraph-mail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Health check to SSL certification
A simple PHP package for sending messages to Microsoft Teams
Laravel 5 Queue Driver for Microsoft Azure Storage Queue
Keeps track of the UTM parameters
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-03