定制 empinet/laravel-outbound-mail-log 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

empinet/laravel-outbound-mail-log

Composer 安装命令:

composer require empinet/laravel-outbound-mail-log

包简介

Log outbound emails sent by Laravel into a database table.

README 文档

README

Tests Quality Latest Version on Packagist Total Downloads

Log outbound emails sent by Laravel into a database table.

This package listens to Laravel's mail sending events and stores outgoing email metadata (subject, recipients, sender, body, headers, attachments, mailable/notification class, mailer, and send status) so you can inspect what was sent.

What gets logged

  • subject
  • from / to / cc / bcc
  • HTML or text body (configurable)
  • headers (configurable)
  • attachment filenames
  • mailable or notification class (when available)
  • mailer name
  • status (sending then sent)
  • sent timestamp

Installation

Install the package with Composer:

composer require empinet/laravel-outbound-mail-log

Publish and run the migration:

php artisan vendor:publish --tag="outbound-mail-log-migrations"
php artisan migrate

You can also use the default Laravel migration publish tag:

php artisan vendor:publish --tag="migrations"
php artisan migrate

Publish the config file:

php artisan vendor:publish --tag="outbound-mail-log-config"

You can also use the default Laravel config publish tag:

php artisan vendor:publish --tag="config"

Configuration

The package ships disabled by default.

Set this in your .env:

OUTBOUND_MAIL_LOG_ENABLED=true

Available config options (config/outbound-mail-log.php):

return [
    'enabled' => env('OUTBOUND_MAIL_LOG_ENABLED', false),
    'cleanup_records_after' => env('OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER', false),
    'log_headers' => env('OUTBOUND_MAIL_LOG_LOG_HEADERS', true),
    'log_body' => env('OUTBOUND_MAIL_LOG_LOG_BODY', true),
    'exclude_classes' => [],
];

Excluding specific mailables or notifications

Use exclude_classes to skip logging for specific classes.

'exclude_classes' => [
    App\Mail\PasswordResetMail::class,
    App\Notifications\SensitiveNotification::class,
],

Class matching is exact (fully qualified class name).

Laravel 10 limitation: some legacy build() mailables do not expose mailable class metadata during MessageSending, so class-based exclusion may not apply for those emails.

Recommended .env values for local/testing:

OUTBOUND_MAIL_LOG_ENABLED=true
OUTBOUND_MAIL_LOG_LOG_BODY=true
OUTBOUND_MAIL_LOG_LOG_HEADERS=true
OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER=false

For production, consider setting OUTBOUND_MAIL_LOG_LOG_BODY=false if emails may contain sensitive content.

Usage

After installing, publishing migrations, and enabling the package, send mail normally using Laravel mailables/notifications.

use Illuminate\Support\Facades\Mail;

Mail::raw('Hello from the app', function ($message): void {
    $message->to('user@example.com')
        ->from('noreply@example.com')
        ->subject('Test message');
});

Then inspect logs from your app:

use Empinet\OutboundMailLog\Models\OutboundMailLog;

$latest = OutboundMailLog::query()
    ->latest('id')
    ->first();

Cleanup command

To remove old records based on OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER, run:

php artisan outbound-mail-log:cleanup

Set OUTBOUND_MAIL_LOG_CLEANUP_RECORDS_AFTER=false to disable cleanup.

To schedule cleanup daily, add this in your routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('outbound-mail-log:cleanup')->daily();

Notes

  • A log entry is created when sending starts (sending) and marked as sent after Laravel dispatches MessageSent.
  • The package supports Mailables, Notification mail channel messages, and closure/raw emails.

Testing

composer test

Releasing

  • Releases are tag-based.
  • Every push to master triggers the release workflow and creates the next patch tag automatically.
  • If no tag exists yet, the workflow bootstraps the first release at v1.0.0.
  • You can also run the release workflow manually and pass an explicit version like 1.2.0.
  • Packagist updates are handled via Packagist auto-update integration.

If Composer shows could not detect the root package version in local development, that is normal before your first release tag. It does not affect package behavior.

Changelog

Please see CHANGELOG for recent changes.

License

The MIT License (MIT). See LICENSE.

empinet/laravel-outbound-mail-log 适用场景与选型建议

empinet/laravel-outbound-mail-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「log」 「mail」 「email」 「laravel」 「empinet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 empinet/laravel-outbound-mail-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 empinet/laravel-outbound-mail-log 我们能提供哪些服务?
定制开发 / 二次开发

基于 empinet/laravel-outbound-mail-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 205
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-29