ag84ark / aws-ses-bounce-complaint-handler
Helper for handling AWS SES with SNS
Requires
- guzzlehttp/guzzle: ^6.5|^7.0
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.1
- orchestra/testbench: ~3|~4|~5
- phpunit/phpunit: ~7|~8
- sempro/phpunit-pretty-print: ^1.0
This package is auto-updated.
Last update: 2024-10-29 05:53:46 UTC
README
Helper for handling AWS SES with SNS This works with HTTP(S) calls or SQS, HTTP(S) recommended! Take a look at contributing.md to see a to do list.
Installation
Via Composer
$ composer require ag84ark/aws-ses-bounce-complaint-handler
Publish the migration and run them with:
php artisan vendor:publish --provider="ag84ark\AwsSesBounceComplaintHandler\AwsSesBounceComplaintHandlerServiceProvider" --tag="migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="ag84ark\AwsSesBounceComplaintHandler\AwsSesBounceComplaintHandlerServiceProvider" --tag="config"
Add the route to the except list in App\Http\Middleware\VerifyCsrfToken.php
class VerifyCsrfToken extends Middleware { protected $except = [ // ... 'amazon-sns/notifications' ]; }
Add link in AWS SNS for AWS SES email bounce and complains to: /amazon-sns/notifications
Also be sure to check the Enable raw message delivery option
Usage
Check to see if it is safe to send email
$email = "me@example.com"; AwsSesBounceComplaint::canSendToEmail($email);
To stop emails from being sent to unsafe email addresses automatically
Add in App\Providers\EventServiceProvider.php
class EventServiceProvider { protected $listen = [ // ... Illuminate\Mail\Events\MessageSending::class => [ App\Listeners\CheckEmailAddressBeforeSending::class, ], ]; }
In 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; } }
To be able to resend to a "banned" email address use
$email = "me@example.com"; AwsSesBounceComplaint::ignoreEmail($email);
This will mark the entries to be ignored when running canSendToEmail but will only work if you run this after the email address was marked as bad. Useful in development.
To remove all entries of an email
$email = "me@example.com"; AwsSesBounceComplaint::clearEmail($email);
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
Please see the license file for more information.