tompec/laravel-email-log

一个用于记录发送邮件的Laravel扩展包

v1.0.3 2020-04-01 02:15 UTC

This package is auto-updated.

Last update: 2024-09-23 01:51:29 UTC


README

Latest Version on Packagist Build Status Quality Score Coverage StyleCI Total Downloads

laravel-email-log 用于记录发送给用户的邮件。如果您使用MailGun,还可以跟踪投递、失败、打开和点击情况。

安装

使用Composer安装此包

composer require tompec/laravel-email-log

如果您使用Laravel 5.5+,则包会自动注册,否则,请将以下内容添加到您的 config/app.php

'providers' => [
    Tompec\EmailLog\EmailLogServiceProvider::class,
],

运行迁移

php artisan migrate

配置(可选)

发布配置文件

php artisan vendor:publish --provider="Tompec\EmailLog\EmailLogServiceProvider"

以下是配置文件的内容。

return [
    /*
     * This is the name of the table that will be created by the migration.
     */
    'table_name' => 'email_log',

    /*
     * The model that will be attached to the email logs.
     */
    'recipient_model' => \App\User::class,

    /*
     * This is the name of the column that the `recipient_model` uses to store the email address.
     */
    'recipient_email_column' => 'email',

    /*
     * Whether or not you want to log emails that don't belong to any model
     */
    'log_unknown_recipients' => true,
];

如果您想获取某个用户的全部邮件日志,请将以下内容添加到您的 App\User.php 文件(或您选择的 recipient_model 模型)

public function email_logs()
{
    return $this->morphMany(\Tompec\EmailLog\EmailLog::class, 'recipient');
}

然后您可以使用 App\User::find(1)->email_logs 获取该用户收到的所有邮件。

Webhooks

如果您使用 Mailgun,您可以跟踪以下4个事件:deliveredopenedclickedpermanent_fail

将以下URL 作为新的Webhook 添加。

https://www.yourdomain.com/email-log/mailgun

Laravel Nova

如果您使用 Laravel Nova,您可以创建一个新的资源来查看表格内容

php artisan nova:resource EmailLog

然后粘贴以下内容以快速设置:此 gist

测试

composer test

更新日志

请参阅 CHANGELOG 了解最近的变化。

贡献

请参阅 CONTRIBUTING 获取详细信息。

安全性

如果您发现任何安全问题,请通过电子邮件 laravel-email-log@mail.tompec.com 反馈,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅 许可证文件