fakeeh/laravel-secure-email
Composer 安装命令:
composer require fakeeh/laravel-secure-email
包简介
Laravel package to monitor and handle AWS SES email complaints, bounces, and deliveries via SNS notifications - Laravel 13 compatible
README 文档
README
A production-ready Laravel package to monitor and handle AWS SES email complaints, bounces, and deliveries via SNS notifications. Automatically prevents sending emails to addresses that have bounced or complained.
Compatible with Laravel 13 (PHP 8.3+)
Features
- ✅ Automatic Email Blocking: Prevents sending to emails with bounces/complaints
- ✅ SNS Webhook Handling: Processes bounce, complaint, and delivery notifications
- ✅ Auto Subscription Confirmation: Automatically confirms SNS subscriptions
- ✅ Flexible Configuration: Customize rules for bounces and complaints
- ✅ Event System: Fire events for bounces, complaints, and deliveries
- ✅ Database Storage: Store all notifications for analysis
- ✅ Permanent Bounce Protection: Block emails with permanent bounces immediately
- ✅ Subject-based Filtering: Count bounces/complaints by email subject
- ✅ Time-based Rules: Set time windows for counting notifications
- ✅ Laravel 13 Compatible: Built for Laravel 13 with PHP 8.3+
Requirements
- PHP 8.3 or higher
- Laravel 13.x
- AWS SES account with SNS configured
Installation
Step 1: Install via Composer
composer require fakeeh/laravel-secure-email
Step 2: Publish Configuration and Migrations
# Publish config file php artisan vendor:publish --tag=secure-email-config # Publish migrations (optional, auto-loaded by default) php artisan vendor:publish --tag=secure-email-migrations # Run migrations php artisan migrate
This will create two tables:
sns_subscriptions- Stores SNS subscription confirmation requestsses_notifications- Stores bounce, complaint, and delivery notifications
Step 3: Configure Your Environment
Add these variables to your .env file:
# Enable/disable the package SES_MONITOR_ENABLED=true # Auto-confirm SNS subscriptions SES_MONITOR_AUTO_CONFIRM=true # Validate SNS message signatures SES_MONITOR_VALIDATE_SNS=true # Route configuration SES_MONITOR_ROUTE_PREFIX=aws/sns/ses SES_MONITOR_BOUNCES_ROUTE=bounces SES_MONITOR_COMPLAINTS_ROUTE=complaints SES_MONITOR_DELIVERIES_ROUTE=deliveries # Bounce rules SES_MONITOR_CHECK_BOUNCES=true SES_MONITOR_MAX_BOUNCES=3 SES_MONITOR_CHECK_BOUNCES_BY_SUBJECT=false SES_MONITOR_BLOCK_PERMANENT_BOUNCES=true SES_MONITOR_BOUNCE_DAYS=30 # Complaint rules SES_MONITOR_CHECK_COMPLAINTS=true SES_MONITOR_MAX_COMPLAINTS=1 SES_MONITOR_CHECK_COMPLAINTS_BY_SUBJECT=true SES_MONITOR_COMPLAINT_DAYS=0
AWS Configuration
Step 1: Create SNS Topics
In your AWS SNS console, create three HTTP/HTTPS topics:
- Bounces Topic:
https://yourdomain.com/aws/sns/ses/bounces - Complaints Topic:
https://yourdomain.com/aws/sns/ses/complaints - Deliveries Topic:
https://yourdomain.com/aws/sns/ses/deliveries
Step 2: Configure SES to Send Notifications
- Go to AWS SES Console
- Select your verified domain or email
- Click "Notifications" → "Edit Configuration"
- Set the SNS topics:
- Bounces: Select your bounces SNS topic
- Complaints: Select your complaints SNS topic
- Deliveries: Select your deliveries SNS topic (optional)
Step 3: Subscription Confirmation
The package will automatically confirm subscriptions when auto-confirm is enabled. If not, you can:
# View unconfirmed subscriptions php artisan secure-email:subscribe-urls # Or manually visit the SubscribeURL in your database
Usage
Basic Usage
Once installed and configured, the package works automatically:
- Incoming Notifications: AWS SNS sends notifications to your endpoints
- Storage: Notifications are stored in the
ses_notificationstable - Email Interception: Before sending any email, the package checks if the recipient should be blocked
- Blocking: Emails to blocked addresses are prevented from sending
Checking if an Email is Blocked
use Fakeeh\SecureEmail\Models\SesNotification; // Check for permanent bounces if (SesNotification::hasPermanentBounce('[email protected]')) { // Don't send email } // Count bounces for an email $bounceCount = SesNotification::countBouncesForEmail('[email protected]'); // Count bounces with subject filter $bounceCount = SesNotification::countBouncesForEmail( '[email protected]', 'Weekly Newsletter', 30 // days ); // Count complaints $complaintCount = SesNotification::countComplaintsForEmail('[email protected]');
Querying Notifications
use Fakeeh\SecureEmail\Models\SesNotification; // Get all bounces $bounces = SesNotification::bounces()->get(); // Get permanent bounces $permanentBounces = SesNotification::permanentBounces()->get(); // Get complaints for a specific email $complaints = SesNotification::complaints() ->forEmail('[email protected]') ->get(); // Get recent notifications (last 30 days) $recent = SesNotification::recent(30)->get(); // Get notifications with specific subject $notifications = SesNotification::withSubject('Newsletter')->get(); // Get deliveries $deliveries = SesNotification::deliveries()->get();
Listening to Events
The package fires events when notifications are received:
use Fakeeh\SecureEmail\Events\SesBounceReceived; use Fakeeh\SecureEmail\Events\SesComplaintReceived; use Fakeeh\SecureEmail\Events\SesDeliveryReceived; // In your EventServiceProvider protected $listen = [ SesBounceReceived::class => [ YourBounceListener::class, ], SesComplaintReceived::class => [ YourComplaintListener::class, ], SesDeliveryReceived::class => [ YourDeliveryListener::class, ], ];
Example listener:
namespace App\Listeners; use Fakeeh\SecureEmail\Events\SesBounceReceived; class HandleSesBounce { public function handle(SesBounceReceived $event) { $notification = $event->getNotification(); $email = $event->getEmail(); if ($event->isPermanent()) { // Handle permanent bounce // e.g., mark user as unsubscribed } } }
Configuration
Bounce Rules
'rules' => [ 'bounces' => [ 'enabled' => true, 'max_bounces' => 3, // Block after 3 bounces 'check_by_subject' => false, // Count all bounces or just same subject 'block_permanent_bounces' => true, // Block permanent bounces immediately 'days_to_check' => 30, // Only count bounces in last 30 days (0 = all time) ], ],
Complaint Rules
'rules' => [ 'complaints' => [ 'enabled' => true, 'max_complaints' => 1, // Block after 1 complaint 'check_by_subject' => true, // Count complaints by subject 'days_to_check' => 0, // Count all complaints (0 = all time) ], ],
Custom Models
You can use your own models by extending the package models:
// In your config/secure-email.php 'models' => [ 'subscription' => App\Models\CustomSnsSubscription::class, 'notification' => App\Models\CustomSesNotification::class, ],
Custom Routes
Customize the webhook endpoints:
// In your config/secure-email.php 'route_prefix' => 'webhooks/ses', 'routes' => [ 'bounces' => 'bounce-notifications', 'complaints' => 'complaint-notifications', 'deliveries' => 'delivery-notifications', ],
This will create endpoints like:
https://yourdomain.com/webhooks/ses/bounce-notificationshttps://yourdomain.com/webhooks/ses/complaint-notificationshttps://yourdomain.com/webhooks/ses/delivery-notifications
Testing
composer test
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Inspired by oza75/laravel-ses-complaints
- Built for Laravel 13 compatibility
License
The MIT License (MIT). Please see License File for more information.
Changelog
Please see CHANGELOG for recent changes.
Support
- Laravel 13.x
- PHP 8.3+
For older Laravel versions, please use a different package.
Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
fakeeh/laravel-secure-email 适用场景与选型建议
fakeeh/laravel-secure-email 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 224 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「monitoring」 「aws」 「bounce」 「laravel」 「ses」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fakeeh/laravel-secure-email 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fakeeh/laravel-secure-email 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fakeeh/laravel-secure-email 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Elastic Driver for Laravel Scout
SoftWax Health Check Bundle for Symfony framework
simple api library.
1Pilot client for Symfony
统计信息
- 总下载量: 224
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-24