symfony/amazon-mailer
Symfony Amazon Mailer bridges the Mailer component with Amazon SES, letting you send emails through AWS using a native transport. Configure credentials and region, then use Symfony Mailer APIs to deliver transactional and bulk messages reliably via SES.
Installation:
composer require symfony/amazon-mailer
Ensure your project uses Symfony Mailer (v5.4+) or Laravel's SwiftMailer bridge (if migrating).
Configuration:
Add AWS SES credentials to .env:
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=us-east-1
MAIL_MAILER=amazon_ses
First Use Case:
Send a test email via Laravel’s Mail facade:
use Illuminate\Support\Facades\Mail;
use App\Mail\TestEmail;
Mail::to('recipient@example.com')->send(new TestEmail());
config/mail.php (ensure amazon_ses transport is configured).vendor/symfony/amazon-mailer (source for transport logic).Sending Emails:
Mail facade or SwiftMailer directly.AmazonSesTransport in config/mail.php:
'transports' => [
'amazon_ses' => [
'scheme' => 'amazon_ses',
'host' => env('AWS_DEFAULT_REGION'),
'path' => '/',
'aws' => [
'version' => 'latest',
'region' => env('AWS_DEFAULT_REGION'),
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
],
],
],
],
Templates & Attachments:
Mailable classes for templates (Blade/HTML).$mailable->attach(public_path('file.pdf'));
Queueing Emails:
Mail::later(now()->addMinutes(5), new TestEmail(), $queue: 'emails');
$mailer->getTransport()->getLogger()->setLevel(\Psr\Log\LogLevel::DEBUG);
log) in config/mail.php for SES outages:
'fallback' => [
'transport' => 'log',
],
AWS SES Limits:
Region Mismatch:
AWS_DEFAULT_REGION matches the SES region (e.g., us-east-1 for SES).TLS/SSL Warnings:
Queue Stuck Jobs:
php artisan queue:work).\Symfony\Component\Mailer\Transport\AmazonSesTransport::class => [
'logger' => \Psr\Log\LoggerInterface::class,
'logger.level' => \Psr\Log\LogLevel::DEBUG,
],
Custom Transport Options:
Extend AmazonSesTransport to add features (e.g., custom headers):
$transport = new AmazonSesTransport($client, [
'headers' => ['X-Custom-Header' => 'value'],
]);
Event Listeners:
Hook into Symfony’s MessageSentEvent for analytics:
Mail::sent(function ($message) {
// Log or track sent emails.
});
Bounce/Complaint Handling: Use AWS SES notifications (SNS) to process bounces/complaints via Laravel events.
How can I help you explore Laravel packages today?