ag84ark/aws-ses-bounce-complaint-handler

处理 AWS SES 与 SNS 的辅助工具

0.4.0 2020-07-28 18:51 UTC

This package is auto-updated.

Last update: 2024-09-29 05:36:26 UTC


README

GitHub build status Latest Version on Packagist Total Downloads Build Status StyleCI Scrutinizer Code Quality Code Coverage

处理 AWS SES 与 SNS 的辅助工具。此工具支持 HTTP(S) 调用或 SQS,推荐使用 HTTP(S)!请查看 contributing.md 以查看待办事项列表。

安装

通过 Composer

$ composer require ag84ark/aws-ses-bounce-complaint-handler

发布迁移并运行它们

php artisan vendor:publish --provider="ag84ark\AwsSesBounceComplaintHandler\AwsSesBounceComplaintHandlerServiceProvider" --tag="migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="ag84ark\AwsSesBounceComplaintHandler\AwsSesBounceComplaintHandlerServiceProvider" --tag="config"

将路由添加到 App\Http\Middleware\VerifyCsrfToken.php 中的排除列表

class VerifyCsrfToken extends Middleware
{
    protected $except = [
        // ... 
        'amazon-sns/notifications'
    ];
}

在 AWS SNS 中添加链接,以便将 AWS SES 邮件退订和投诉发送到:/amazon-sns/notifications
同时,请确保选中 启用原始消息传输 选项

使用方法

检查是否安全发送邮件

$email = "me@example.com";
AwsSesBounceComplaint::canSendToEmail($email);

自动阻止将邮件发送到不安全的电子邮件地址

在 App\Providers\EventServiceProvider.php 中添加

class EventServiceProvider {

    protected $listen = [
        // ...
        Illuminate\Mail\Events\MessageSending::class => [
            App\Listeners\CheckEmailAddressBeforeSending::class,
        ],
    ];
}

在 App\Listeners\CheckEmailAddressBeforeSending.php 中

<?php
 
 namespace App\Listeners;
 
 use ag84ark\AwsSesBounceComplaintHandler\AwsSesBounceComplaintHandler;
 use Illuminate\Mail\Events\MessageSending;
 
 class CheckEmailAddressBeforeSending
 {
     public function __construct()
     {
         //
     }
 
     public function handle(MessageSending $event): bool
     {
         $email = $event->data['email'];
         if (!AwsSesBounceComplaintHandler::canSendToEmail($email)) {
             \Log::info(json_encode($event->data));
             // log the information in some way   
             return false;
         }
 
 
         return true;
 
     }
 }

要能够重新发送到“被禁止”的电子邮件地址,请使用

$email = "me@example.com";
AwsSesBounceComplaint::ignoreEmail($email);

这将标记条目以便在运行 canSendToEmail 时忽略,但只有在标记电子邮件地址为不良后运行此操作才会起作用。在开发中很有用。

删除电子邮件的所有条目

$email = "me@example.com";
AwsSesBounceComplaint::clearEmail($email);

变更日志

请参阅 changelog 以了解最近更改的信息。

测试

$ composer test

贡献

请参阅 contributing.md 了解详细信息以及待办事项列表。

安全

如果您发现任何安全相关的问题,请通过作者的电子邮件而不是使用问题跟踪器来联系。

鸣谢

许可

请参阅 许可文件 了解更多信息。