filippo-toso/laravel-mailog
Composer 安装命令:
composer require filippo-toso/laravel-mailog
包简介
Log your emails to the database and view them in a simple web interface
README 文档
README
This package allows you to store all your application outgoing email into a database and (optionally) view them using the integrated Web UI.
You can use it as a mail transport (no email is delivered) or as an event listener (all emails are delivered normally but also logged into the database).
Why does this exist?
Maybe you are asking yourself why I built this package when there's the log driver or services like Mailtrap, etc.
I work with a lot of institutional customers (banks, public bodies, you name it...). These customers are very picky about where their data is stored (ie. Are Mailtrap data centers in the EU? How are they secured? Who has access to them? And the list goes on, and on, and on...). This package offers a self-hosted solution that works perfectly in both test and production environments and meets their stringent requirements.
Installation
Install the package using composer:
composer require filippo-toso/laravel-mailog
If you want/need to customize the configuration (ie. use a different database for the logging, etc.), publish the configuration file and change it accordingly:
php artisan vendor:publish --tag="mailog-config"
Publish the migrations and change them accordingly:
php artisan vendor:publish --tag="mailog-migrations"
Then, execute the migrations:
php artisan migrate
Use it as a Mail Transport
In your config/mail.php file add the mailog mailer as shown below.
return [ // ... 'mailers' => [ // ... 'mailog' => [ 'transport' => 'mailog', ], ], ];
Then edit your .env file as follows:
MAIL_MAILER=mailog
Use it as an Event Listener
Just edit the config/mailog.php file as follows:
'listen' => true,
Access the Web UI
If you want to use the built-in web UI, you can register the routes in your web.php file.
Then you'll be able to access the UI using the /mailog/messages url.
Route::middleware('auth')->group(function () { // ... \FilippoToso\LaravelMailog\Support\MailogRoutes::register(); });
If you want to customize the UI, you can publish the views as follows:
php artisan vendor:publish --tag="mailog-views"
You can also override the FilippoToso\LaravelMailog\Http\Controllers\MessageController class and change its behaviour. For instance you could add a filter for your tenant:
use FilippoToso\LaravelMailog\Http\Controllers\Concerns\IsMailogController; class MailogMessageController extends Controller { use IsMailogController { query as mailogQuery; } /** * The query that filters the messages * * @param array $filters * @return Builder */ protected function query(array $filters) { return parent::mailogQuery() ->where('tenant_id','=', tenant('id')); } }
Then you have to update your routes file to point to the right controller.
You can take inspiration from the FilippoToso\LaravelMailog\Support\Routes::register() method.
Overriding the Mail Transport behaviour
In the config/mailog.php file you can specify a class to use as a transport. For instance, you can override the provided MailogTransport class and add the support for tenancy as follows:
use FilippoToso\LaravelMailog\Transport\MailogTransport; use Symfony\Component\Mime\Email; class MailogTransportWithTenant extends MailogTransport { /** * Build the message data to be stored in the database * You can override this method to add more fields to the message * * @param $messageId * @param Email $converdedEmail * @return array */ protected function messageData(string $messageId, Email $converdedEmail) { return array_merge(parent::messageData($messageId, $converdedEmail),[ 'tenant_id' => tenant('id'), ]); } }
Please beware, the use of tenant('id') for identifing the tenant foreign key is just an example taken from the stancl/tenancy package. Depending on how you are implementing the tenancy, you should adapt the code as needed.
Other useful things to know
The package includes a mailog:purge-messages command. You can schedule it in the scheduler and configure its behaviour in the purge section of the config/mailog.php file
filippo-toso/laravel-mailog 适用场景与选型建议
filippo-toso/laravel-mailog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filippotoso」 「laravel-mailog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 filippo-toso/laravel-mailog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 filippo-toso/laravel-mailog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-25