Setting up Amazon Simple Email Service (SES) to send emails from your Laravel application is a highly scalable, robust, and cost-effective approach. Laravel integrates natively with AWS SES using two methods: **SMTP Relay** or the **AWS SES API Driver**.
This guide covers the quick setup for SMTP routing, configuring your mailer settings in Laravel 10/11, and updating environment variables.
---
## 1. Generating SMTP Credentials in AWS SES
To authenticate your application with the AWS SMTP servers, you must generate a set of IAM credentials specifically for SMTP:
1. Open the **AWS SES Console**.
2. Click on **SMTP settings** in the left sidebar.
3. Click the **Create SMTP credentials** button.
4. AWS will create a new IAM user for your account. Accept the default user name and click **Create**.
5. Copy your **SMTP Username** and **SMTP Password**. *Note: These are different from your regular AWS access key ID and secret access key.*
---
## 2. Configuration Settings in `.env`
Once you have your credentials, update your application's environment configuration `.env` file:
```env
MAIL_MAILER=smtp
MAIL_HOST=email-smtp.us-east-1.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=AKIAXXXXXXXXXXXXXXXX
MAIL_PASSWORD=BpXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="Solidrix Send"
```
> [!WARNING]
> Ensure that `MAIL_FROM_ADDRESS` is a verified email address or verified domain in your AWS SES console. Sending from an unverified address will throw a `554 Message rejected: Email address is not verified` error.
---
## 3. Optimizing Configuration files
Verify your `config/mail.php` has the standard SMTP mailer driver configuration. Laravel has this configured by default:
```php
'mailers' => [
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'mailpit'),
'port' => env('MAIL_PORT', 1025),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN'),
],
],
```
Run the config clear command to apply changes:
```bash
php artisan config:clear
```
Now, your Laravel app is fully prepared to deliver all transactional emails, register notifications, and password resets securely via AWS SES SMTP servers.