cleaniquecoders / mailhistory
跟踪您Laravel应用程序中发送的所有电子邮件。
2.1.0
2024-03-21 04:14 UTC
Requires
- php: ^8.1 | ^8.2 | ^8.3
- illuminate/contracts: ^9.0 | ^10.0 | ^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.1|^7.9
- orchestra/testbench: ^8.0
- pestphp/pest: ^1.21|^2.0
- pestphp/pest-plugin-laravel: ^1.4|^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
此包将允许您捕获使用Laravel中的邮件或通知功能发送的任何邮件。
安装
您可以通过composer安装此包
composer require cleaniquecoders/mailhistory
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="mailhistory-migrations"
php artisan migrate
如果您需要配置更多,请发布配置文件并根据需要更新配置文件。
php artisan vendor:publish --tag="mailhistory-config"
使用
我们需要配置两个部分 - 邮件 & 通知。
邮件
所有邮件都必须使用邮件元数据特质。
<?php namespace App\Mail; use CleaniqueCoders\MailHistory\Concerns\InteractsWithMailMetadata; class DefaultMail extends Mailable { use InteractsWithMailMetadata, SerializesModels;
并在您的邮件构造函数中调用以下方法
public function __construct() { $this->configureMetadataHash(); }
通过这种设置,我们可以跟踪哪些邮件已被发送或仍在发送。
通知
在此步骤之前配置您的邮件。目前,它仅适用于Mailable,不适用于Mail Message类。
对于通知类,您需要添加以下特质
use CleaniqueCoders\MailHistory\Concerns\InteractsWithMail; class DefaultNotification extends Notification { use InteractsWithMail;
然后在您的通知构造函数中,您需要初始化邮件对象。
public function __construct() { $this->setMail( new \App\Mails\DefaultMail ); }
并更新toMail()
如下
/** * Get the mail representation of the notification. */ public function toMail(object $notifiable): Mailable { return $this->getMail()->to($notifiable->email); }
Artisan命令
如果您需要清理邮件历史表,可以运行
php artisan mailhistory:clear
如果您需要测试邮件或通知
php artisan mailhistory:test you-email@app.com --mail php artisan mailhistory:test you-email@app.com --notification
请注意,对于邮件测试,您需要一个具有电子邮件地址的用户记录,因为我们正在使用Notifiable特质。
您可以使用指定队列运行测试
php artisan mailhistory:test you-email@app.com --mail --queue=mail
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
请查看我们如何报告安全漏洞的安全策略。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。