oza75/laravel-ses-complaints

Laravel SES 投诉和退信管理器

v1.0.0 2024-02-26 01:32 UTC

This package is auto-updated.

Last update: 2024-09-26 02:46:14 UTC


README

Latest Version on Packagist Total Downloads GitHub Actions

此包监听 AWS SNS 通知,并停止向收到永久退信通知的电子邮件地址或标记为垃圾邮件的用户发送邮件。

工作原理

此包拦截您 laravel 应用程序发送的每封邮件,并检查接收者是否未将您的邮件标记为 SPAM,或者用户电子邮件地址是否在之前收到 AWS SNS 的永久退信通知。然后根据您在 配置文件 中定义的策略,停止邮件发送过程或发送邮件。

安装

在安装过程之前,请参考下表中的版本映射表,以确认 laravel-ses-complaints 包版本与您的 Laravel 应用程序之间的兼容性

确保您选择与您的 Laravel 版本相对应的适当版本,以保证完整的功能和兼容性。

您可以通过 composer 安装此包

composer require oza75/laravel-ses-complaints

发布迁移文件和配置文件

php artisan vendor:publish --provider="Oza75\LaravelSesComplaints\LaravelSesComplaintsServiceProvider"

运行迁移

php artisan migrate

此命令将在您的数据库中创建 2 个表。用于 SNS 订阅确认请求的 sns_subscriptions 表,以及用于存储从 SNS 收到的投诉和退信通知的 ses_notifications 表。

用法

创建 SNS 主题

访问您的 AWS SNS 控制台,并创建两个具有以下端点的 HTTP/S 主题

您可以在 配置文件 中自定义这些端点。请注意,一旦您创建了这些端点,它们将被自动确认。如果不这样做,您可以使用 php artisan aws:sns:subscribe-url 命令打印出直接在您的 aws 控制台中确认订阅所需的 SubscribeURL。更多信息请参考这里

创建 SNS 主题

将 SNS 主题添加到您的 SES 域。更多信息请参考这里

配置文件

<?php

return [
    /**
     * If enabled is set to true, this package will intercept each mail then check
     * if the mail passes all middlewares defined in this config file. It will also
     * listen to sns notifications and store them in database. You may set enabled to false
     * to completed disabled this package
     */
    'enabled' => true,
    /*
     * Models used to created a new subscription confirmation request and
     * to store a sns notification received from aws.
     */
    'models' => [
        'subscription' => \Oza75\LaravelSesComplaints\Models\Subscription::class,
        'notification' => \Oza75\LaravelSesComplaints\Models\Notification::class,
    ],

    /**
     * Routes used to handle bounces notification and complaints notifications
     */
    'routes' => [
        'bounces' => '/aws/sns/ses/bounces',
        'complaints' => '/aws/sns/ses/complaints',
    ],

    // Controller used to handle all actions. You can override this if you want to add
    // more specific logic
    'controller' => \Oza75\LaravelSesComplaints\Controllers\SNSController::class,

    /**
     * An array of middleware that the email will go through. If only one return false
     * we do not send the email. All middlewares must implement the \Oza75\LaravelSesComplaints\Contracts\CheckMiddleware::class
     * interface.
     */
    'middlewares' => [
        \Oza75\LaravelSesComplaints\Middlewares\ComplaintCheckMiddleware::class => [
            /**
             * The max number of sns complaint notification before stop sending email to the user
             */
            'max_entries' => 1,
            /**
             * If the check_by_subject is set to true, we will count
             * the amount of complaint notification  received from sns and that has the same subject as
             * the email we are trying to send. If the count is greater or equal to max_entry we don't send
             * the email.
             */
            'check_by_subject' => true,
        ],
        \Oza75\LaravelSesComplaints\Middlewares\BounceCheckMiddleware::class => [
            /**
             * The max number of sns bounced notification before stop sending email to the user
             */
            'max_entries' => 3,
            /**
             * If the check_by_subject is set to true, we will count
             * the amount of bounced notification  received from sns and that has the same subject as
             * the email we are trying to send. If the count is greater or equal to max_entry we don't send
             * the email.
             */
            'check_by_subject' => false,
        ]
    ],
];

测试

composer test

更新日志

请参阅更新日志以获取有关最近更改的更多信息。

贡献

请参阅贡献指南以获取详细信息。

安全

如果您发现任何与安全相关的问题,请通过电子邮件abouba181@gmail.com报告,而不是使用问题跟踪器。

鸣谢

许可协议

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

Laravel 包模板

此包是用Laravel 包模板生成的。