pod-point / laravel-mail-export
一个可导出邮件到存储磁盘的邮件发送特质
2.1.0
2023-09-01 09:37 UTC
Requires
- php: ^8.1
- illuminate/filesystem: ^9.0|^10.0
- illuminate/mail: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
- nesbot/carbon: ^2.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0
README
此包可以将使用 Laravel 的 Mailable
类发送的任何邮件导出为 .eml
文件到任何指定的文件系统磁盘和路径。
这在需要存储用于存档目的发送的电子邮件时非常有用。
安装
您可以通过 composer 安装此包
对于 Laravel 9.x 和 10.x
composer require pod-point/laravel-mail-export
对于 Laravel 7.x 和 8.x
composer require pod-point/laravel-mail-export:^1.0
对于 Laravel 5.x 和 6.x
composer require pod-point/laravel-mail-export:^0.1
发布配置文件
此包的配置包含一些合理的默认值,但您可以选择使用以下命令发布配置文件:
php artisan vendor:publish --provider="PodPoint\MailExport\MailExportServiceProvider"
您将能够指定
enabled
:是否启用此包。安装后默认启用,但可以使用MAIL_EXPORT
环境变量进行配置。disk
:默认使用的磁盘。默认为应用程序文件系统中的默认磁盘。path
:邮件导出到配置磁盘中的默认路径。
有关更多详细信息,请参阅我们的 config/mail-export.php
。
使用方法
只需将 Exportable
特质和 ShouldExport
接口添加到您希望持久保存到任何存储磁盘的任何 Mailable 类。
<?php namespace App\Mail; use Illuminate\Mail\Mailable; use PodPoint\MailExport\Concerns\Exportable; use PodPoint\MailExport\Contracts\ShouldExport; class OrderShipped extends Mailable implements ShouldExport { use Exportable; // ... }
这将使用配置中的默认 disk
和 path
,并为您生成一个唯一的 filename
。
默认的文件名使用时间戳、邮件收件人、主题,如下所示:
2021_03_26_150142_jane_at_example_com_this_is_the_subject.eml
您也可以使用属性为特定的 Mailable 指定 disk
、path
或 filename
。
<?php namespace App\Mail; use Illuminate\Mail\Mailable; use PodPoint\MailExport\Concerns\Exportable; use PodPoint\MailExport\Contracts\ShouldExport; class OrderShipped extends Mailable implements ShouldExport { use Exportable; public $exportDisk = 'some_disk'; public $exportPath = 'some_path'; public $exportFilename = 'some_filename'; // ... }
如果您需要更多灵活性,也可以使用方法
<?php namespace App\Mail; use Illuminate\Mail\Mailable; use PodPoint\MailExport\Concerns\Exportable; use PodPoint\MailExport\Contracts\ShouldExport; class OrderShipped extends Mailable implements ShouldExport { use Exportable; // ... public function exportDisk(): string { return 'some_disk'; } public function exportPath(): string { return 'some_path'; } public function exportFilename(): string { return 'some_filename'; } }
然后您可以像平常一样继续使用您的 Mailable
Mail::to($request->user())->send(new OrderShipped($order));
甚至还可以使用通知
<?php namespace App\Notifications; use App\Mail\OrderShipped as Mailable; use Illuminate\Notifications\Notification; class OrderShipped extends Notification { // ... public function toMail($notifiable) { return (new Mailable($this->order))->to($notifiable->email); } }
测试
使用以下命令运行测试:
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的详细信息。
贡献
有关详细信息,请参阅 CONTRIBUTING。
鸣谢
- themsaid 和 Spatie 的 laravel-mail-preview 提供了一些灵感
- Laravel Package Development 文档由 John Braun 提供
- Pod Point
- 所有贡献者
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。
旅行不应破坏地球 🌍
用 ❤️ 在 Pod Point 制作