- How do I integrate AsyncAws SES with Laravel’s Mail facade for async email delivery?
- Use Laravel’s Mail facade as usual, but ensure your queue system is configured. AsyncAws SES automatically dispatches emails to the queue when using Laravel’s Mailer. For example, `Mail::to('user@example.com')->send(new OrderConfirmation($order));` will queue the email for async processing. No additional setup is needed beyond configuring your Laravel queue driver (e.g., database, redis).
- Does AsyncAws SES support Laravel’s event system for email tracking (e.g., Sent, Failed)?
- Yes, AsyncAws SES integrates with Laravel’s event system. You can listen for `MailSent` or `MailFailed` events using Laravel’s `Mail::sent()` or `Mail::failed()` hooks. This allows you to log, retry, or notify other services when emails are sent or fail. Example: `Mail::failed(fn($message) => Log::error('Email failed:', ['message' => $message]));`.
- What Laravel versions and PHP versions does AsyncAws SES support?
- AsyncAws SES requires PHP 8.2+ and is designed for Laravel 9.x or later. It leverages modern PHP features like typed classes, which are not backward-compatible with older Laravel versions (e.g., 8.x). If you’re on an older Laravel version, consider alternatives like the AWS SDK for PHP or upgrading your PHP/Laravel stack.
- How do I configure AsyncAws SES in Laravel’s service container for dependency injection?
- Register the `SesClient` in Laravel’s service container using the `AppServiceProvider`. Example: `$app->singleton(SesClient::class, fn() => new SesClient(['region' => 'us-east-1', 'credentials' => $app['aws.credentials']]));`. This allows you to inject `SesClient` into services or controllers via constructor injection. Ensure your AWS credentials are configured in Laravel’s config or environment files.
- Can I mock AsyncAws SES for testing in Laravel?
- Yes, AsyncAws SES provides a `MockSesClient` for testing. Use Laravel’s `MailFake` facade to simulate email sending without hitting AWS. Example: `Mail::fake(); $this->assertCount(1, Mail::pretend()->to('user@example.com')->send(new TestEmail()));`. For more complex scenarios, replace the `SesClient` binding in your tests with the mock client.
- What AWS SES setup is required before using AsyncAws SES in production?
- You need an AWS account with SES access, verified email addresses/domains, and IAM permissions for `ses:SendEmail`, `ses:SendRawEmail`, and `ses:GetSendStatistics`. Configure DKIM/SPF records for your domain and ensure you’re out of SES sandbox mode (or request production access). AsyncAws SES doesn’t handle AWS setup—this is a prerequisite for sending emails.
- How does AsyncAws SES handle failed email jobs in Laravel?
- Failed email jobs are handled by Laravel’s queue system. Configure `max_attempts` in your queue configuration (default: 3) and set up a dead-letter queue to capture permanently failed jobs. Example: `'failed' => database,` in your `queue.php` config. Monitor the `failed_jobs` table or use Laravel’s `Queue::failed()` to process retries manually.
- Is AsyncAws SES suitable for time-sensitive emails like OTPs or notifications?
- AsyncAws SES adds latency due to queue processing (typically 50–500ms), which may not be ideal for time-sensitive emails like OTPs. For such cases, consider using SES’s synchronous API directly or a dedicated service like Twilio SendGrid. AsyncAws SES is better suited for non-critical emails like digests or marketing campaigns.
- What are the alternatives to AsyncAws SES for Laravel email delivery?
- Alternatives include the official AWS SDK for PHP (`aws/aws-sdk-php`), which supports SES but lacks async-first design, or third-party services like SendGrid, Mailgun, or Postmark. If you need async processing without AWS, consider Laravel’s built-in queue system with a synchronous SMTP driver or a dedicated email service API. Each has trade-offs in cost, setup, and features.
- How do I scale AsyncAws SES for high-volume email campaigns in Laravel?
- Scale by horizontally scaling Laravel queue workers (e.g., using Kubernetes HPA or a queue worker service like Iron.io). Optimize AWS SES by batching emails, monitoring SES throttling limits, and setting up SNS notifications for delivery issues. Use Laravel’s queue batching (`dispatchSync()`) for critical emails and ensure your database/redis queue backend can handle the load.