sinarahmany/laravel-email-monitor
Composer 安装命令:
composer require sinarahmany/laravel-email-monitor
包简介
A comprehensive Laravel package to monitor all outgoing emails with tracking, logging, and dashboard capabilities
README 文档
README
A comprehensive Laravel package to monitor all outgoing emails with tracking, logging, and dashboard capabilities. Built with ❤️ by Sina Rahmannejad.
✨ Features
- 📧 Automatic Email Tracking: Monitors all outgoing emails automatically
- 📊 Dashboard Interface: Beautiful web interface to view email statistics and logs
- 🔍 Advanced Filtering: Filter emails by status, date range, recipient, and more
- 📈 Statistics & Analytics: Detailed statistics and analytics for email performance
- 🔄 Resend Failed Emails: Easy resending of failed emails
- 🗂️ Email Details: View complete email details including body, headers, and metadata
- ⚙️ Zero Configuration: Works out-of-the-box with sensible defaults
- 🧹 Auto Cleanup: Automatic cleanup of old email logs
- 🔔 Webhook Support: Webhook notifications for email status updates
- 🎯 Status Tracking: Track sending, sent, delivered, failed, and bounced statuses
- 🚀 One-Click Setup: Install and configure with a single command
🚀 Quick Start (One-Click Setup)
1. Install the Package
composer require sinarahmany/laravel-email-monitor
2. One-Click Installation
php artisan email-monitor:install
That's it! 🎉 The package will automatically:
- ✅ Publish all assets (config, migrations, views)
- ✅ Create the database migration
- ✅ Run migrations automatically
- ✅ Set up routes
- ✅ Configure environment variables
- ✅ Verify installation
3. Access the Dashboard
Visit: http://your-app.com/email-monitor
4. Test Email Monitoring
Visit: http://your-app.com/test-email to send a test email and see it in the dashboard
🔧 Alternative Setup Methods
Quick Setup (Legacy)
php artisan email-monitor:setup
Force Reinstall
php artisan email-monitor:install --force
Skip Database Setup
php artisan email-monitor:install --skip-migrate
📋 Manual Installation (Optional)
If you prefer manual control:
1. Install the Package
composer require sinarahmany/laravel-email-monitor
2. Publish Configuration
php artisan vendor:publish --tag=email-monitor-config
3. Publish Migrations
php artisan vendor:publish --tag=email-monitor-migrations
4. Run Migrations
php artisan migrate
5. Publish Views (Optional)
php artisan vendor:publish --tag=email-monitor-views
⚙️ Configuration (Optional)
The package works out-of-the-box with sensible defaults. All configuration is optional!
Environment Variables (Optional)
Add these variables to your .env file only if you want to customize:
# Enable/disable email monitoring (default: true) EMAIL_MONITOR_ENABLED=true # Database connection (optional, uses default if not set) EMAIL_MONITOR_CONNECTION=mysql # Log email body content (default: true) EMAIL_MONITOR_LOG_BODY=true # Log metadata (user_id, ip_address, etc.) (default: true) EMAIL_MONITOR_LOG_METADATA=true # Auto cleanup old logs after X days (default: 90) EMAIL_MONITOR_AUTO_CLEANUP_DAYS=90 # Stuck email timeout in minutes (default: 2) EMAIL_MONITOR_TIMEOUT_MINUTES=2 # Webhook configuration (optional) EMAIL_MONITOR_WEBHOOKS_ENABLED=false EMAIL_MONITOR_WEBHOOK_URL= EMAIL_MONITOR_WEBHOOK_SECRET= # Notification configuration (optional) EMAIL_MONITOR_NOTIFICATIONS_ENABLED=false EMAIL_MONITOR_FAILED_THRESHOLD=5
Configuration File
The package includes a comprehensive configuration file at config/email-monitor.php with the following options:
- enabled: Enable/disable email monitoring
- connection: Database connection to use
- table: Table name for email logs
- log_body: Whether to log email body content
- log_metadata: Whether to log additional metadata
- route_prefix: Dashboard route prefix
- middleware: Middleware for dashboard routes
- auto_cleanup_days: Auto cleanup configuration
- track_statuses: Which statuses to track
- webhooks: Webhook configuration
- filters: Email filtering options
- notifications: Notification settings
Usage
Dashboard Access
Once installed, you can access the email monitor dashboard at:
http://your-app.com/email-monitor
API Endpoints
The package provides several API endpoints:
GET /email-monitor/api/statistics- Get email statisticsGET /email-monitor/api/recent- Get recent email logs
Programmatic Access
You can also access email logs programmatically:
use Laravel\EmailMonitor\Models\EmailLog; use Laravel\EmailMonitor\Services\EmailMonitorService; // Get email logs $emailLogs = EmailLog::where('status', 'sent')->get(); // Get statistics $emailMonitorService = app(EmailMonitorService::class); $statistics = $emailMonitorService->getStatistics(30); // Last 30 days // Get recent logs $recentLogs = $emailMonitorService->getRecentLogs(10);
Model Methods
The EmailLog model provides several useful methods:
// Get formatted status $emailLog->formatted_status; // "Sent" // Get status badge class $emailLog->status_badge_class; // "badge-success" // Get time since sent $emailLog->time_since_sent; // "2 hours ago" // Get recipients as array $emailLog->recipients; // ['user@example.com', 'admin@example.com'] // Mark as delivered $emailLog->markAsDelivered(); // Mark as failed $emailLog->markAsFailed('SMTP timeout'); // Mark as bounced $emailLog->markAsBounced('Invalid email address');
Dashboard Features
Statistics Overview
The dashboard provides comprehensive statistics:
- Total emails sent
- Successfully sent emails
- Pending emails
- Failed emails
- Daily statistics
Email Logs Table
View all email logs with:
- Status badges
- Recipient information
- Sender information
- Subject lines
- Sent timestamps
- Action buttons (view, resend, delete)
Filtering and Search
- Filter by status (sending, sent, delivered, failed, bounced)
- Search by recipient, sender, or subject
- Date range filtering
- Pagination support
Email Details
View detailed information for each email:
- Complete email headers
- Full email body
- Timing information
- Error messages (if any)
- Metadata (user_id, ip_address, etc.)
- Action buttons (resend, delete)
Advanced Features
Webhook Support
Configure webhooks to receive real-time notifications:
// In your webhook handler public function handleEmailStatusUpdate($data) { // Handle email status update $emailLog = EmailLog::where('message_id', $data['message_id'])->first(); if ($data['status'] === 'delivered') { $emailLog->markAsDelivered(); } elseif ($data['status'] === 'bounced') { $emailLog->markAsBounced($data['reason']); } }
Custom Middleware
Add authentication or other middleware to the dashboard:
// In config/email-monitor.php 'middleware' => ['web', 'auth', 'admin'],
Email Filtering
Configure which emails to monitor:
// In config/email-monitor.php 'filters' => [ 'exclude_patterns' => [ 'test@example.com', '*@test.com', ], 'include_patterns' => [ // Only monitor emails matching these patterns ], ],
Auto Cleanup
Automatically clean up old email logs:
// In config/email-monitor.php 'auto_cleanup_days' => 90, // Clean up logs older than 90 days
Troubleshooting
Common Issues
- Emails not being logged: Check if
EMAIL_MONITOR_ENABLED=truein your.envfile - Dashboard not accessible: Ensure the package is properly installed and routes are registered
- Database errors: Make sure migrations have been run
Debug Mode
Enable debug mode to see detailed logging:
// In config/email-monitor.php 'debug' => env('EMAIL_MONITOR_DEBUG', false),
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This package is open-sourced software licensed under the MIT license.
Support
For support, please open an issue on GitHub or contact the maintainers.
Changelog
Version 0.2.0
- Initial release
- Basic email monitoring functionality
- Dashboard interface
- Statistics and analytics
- Email filtering and search
- Resend functionality
- Auto cleanup
- Webhook support
sinarahmany/laravel-email-monitor 适用场景与选型建议
sinarahmany/laravel-email-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 378 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「email」 「monitor」 「laravel」 「dashboard」 「tracking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sinarahmany/laravel-email-monitor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sinarahmany/laravel-email-monitor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sinarahmany/laravel-email-monitor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
Collections of statsd collectors with templated metric names
A Laravel package to monitor queue jobs.
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 378
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-24