

# Auth emails

The Amplify backend sends auth emails to your users, such as email verification links and password reset links. To send them from your own address, and to change what they say, connect your own SMTP server.

## Emails the backend sends
<a name="backend-auth-email-list"></a>


| Email | Sent when | Template flow | Required variables | 
| --- | --- | --- | --- | 
| Email verification | A user signs up, an unverified user’s sign-in is refused, or your app calls `resendVerificationEmail`. Your `emailVerification` settings decide which |  `verification`  |  `{{confirmationUrl}}`  | 
| Password reset | A user asks to reset their password |  `resetPassword`  |  `{{resetUrl}}`  | 
| Sign-in link | A user signs in with an email link |  `magicLink`  |  `{{magicLinkUrl}}`  | 
| One-time code | A user asks for an emailed code |  `emailOtp`  |  `{{otp}}`  | 
| Email change | A user changes their email address |  `changeEmail`  |  `{{confirmationUrl}}` and `{{newEmail}}`  | 
| Account deletion | A user deletes their account |  `deleteUser`  |  `{{confirmationUrl}}`  | 

To send verification and reset emails from your app, see [Email and password](backend-auth-password.md).

## Who sends auth emails
<a name="backend-auth-email-sender"></a>

A deployed backend sends the built-in emails from a shared no-reply address, with your `appName` as the sender name. For `appName`, see [Auth configuration](backend-auth-config.md).

The shared sender sends about 100 auth emails for each AWS account, Region, and UTC day, across all of the account’s backends. After that, it sends none until the next UTC day. To send more, use your own SMTP server. The backend sets no daily limit for your own server. For more information about auth email limits, see [Quotas](quotas-chapter.md).

**Note**  
The shared sender drops emails to domains reserved for testing, such as `example.com`. To test with those addresses, use your own SMTP server or the local backend. A request for such an address still succeeds: a sign-up answers `200` and creates an unverified user, but no email goes out, and the access log’s `auth_email_outcome` is `email_refused_reserved_domain`. The reserved domains are `example.com`, `example.net`, `example.org`, and names under `.test`, `.example`, `.invalid`, and `.localhost`.

To send your app’s own emails, such as an order confirmation, call an email provider such as Amazon SES from your server code.

## Send email through your own SMTP server
<a name="backend-auth-email-smtp"></a>

1. Store the SMTP user name and password as backend secrets in each environment that uses the server. A deployment fails with `CONFIG_RETRIEVAL_FAILED` when either value is missing or was stored without `--secret` and `--scope BACKEND`.

   ```bash
   printf %s "$SMTP_USERNAME" | aws amplifygen3 var set SMTP_USERNAME --secret --scope BACKEND --env preview
   printf %s "$SMTP_PASSWORD" | aws amplifygen3 var set SMTP_PASSWORD --secret --scope BACKEND --env preview
   ```

1. Add `platform.customEmail.smtp` to `backend.auth`. To use the server in one environment only, add it to a full `env.<name>.backend.auth` block. That block replaces the root block for that environment, so copy your other auth settings into it.

   ```jsonc
   // amplify.jsonc
   {
     "backend": {
       "auth": {
         "appName": "Acme Notes",
         "emailAndPassword": { "enabled": true },
         "platform": {
           "customEmail": {
             "smtp": {
               "host": "smtp.example.com",
               "port": 587,
               "username": "${env:SMTP_USERNAME}",
               "password": "${env:SMTP_PASSWORD}",
               "from": "Acme Notes <no-reply@example.com>",
               "replyTo": "support@example.com"
             }
           }
         }
       }
     }
   }
   ```

1. Run `aws amplifygen3 deploy`. The backend then sends every auth email through your server, from the `from` address.

**Note**  
The backend doesn’t fall back to the shared sender. A deployment checks the `smtp` block and its secrets, but doesn’t connect to the server. A wrong host, port, user name or password makes each auth email fail when the backend sends it, so send a test email after you deploy.

## Change the email templates
<a name="backend-auth-email-templates"></a>

The backend uses your templates only when `platform.customEmail.smtp` is set. If it isn’t set, `aws amplifygen3 templates validate` and `aws amplifygen3 deploy` warn that the templates aren’t used.

1. Run the following command from the folder that holds `amplify.jsonc`. It writes the built-in English emails to `email-templates/<flow>.html`. Add `--flow <flow>` for one file, or `--force` to overwrite existing files.

   ```bash
   aws amplifygen3 templates scaffold
   ```

1. Edit the files that you want to change, and delete the rest. A flow with no file keeps its built-in email. Each template must use its flow’s required variables, and can also use `{{appName}}`. A first line of `{{!subject: <text>}}` sets the subject.

   ```html
   {{!subject: Confirm your Acme Notes account}}
   <p>Thanks for signing up for {{appName}}.</p>
   <p><a href="{{confirmationUrl}}">Verify your email</a></p>
   ```

1. Check the files, then deploy. A Git deployment reads `email-templates/` at the repository root, so commit the files before you push.

   ```bash
   aws amplifygen3 templates validate
   aws amplifygen3 deploy
   ```

The backend HTML-escapes each variable in the body and writes the email’s plain-text part itself.

**Note**  
To go back to a flow’s built-in emails in every language, delete that flow’s `.html` file and deploy. This works only while `email-templates/` still holds another `.html` file. A deployment with no template files keeps your current templates. The `templates scaffold --flow <flow> --force` command restores only the English email. The backend then sends that English email in every language.

## Send emails in your users' languages
<a name="backend-auth-email-languages"></a>

The built-in emails come in English, Spanish and Simplified Chinese. To send other languages, copy a flow’s file to `email-templates/<flow>.<locale>.html`, such as `verification.fr.html`, and translate it, subject line included. For the locale codes, run `aws amplifygen3 templates scaffold help`.

The backend takes the request’s language from the `X-AmplifyGen3-Locale` header, or else from the browser’s `Accept-Language` header. A request whose `X-AmplifyGen3-Locale` header names a language that the backend doesn’t support fails with `400` `UNSUPPORTED_LOCALE`. No email goes out. For the first language listed, it looks for `<flow>.<locale>.html` (`fr-CA` uses `fr`). If that file is missing, it looks for `<flow>.html`, then the built-in email. Your `<flow>.html` takes priority over the built-in Spanish and Chinese emails. To send Spanish speakers a Spanish email, add a translated file such as `verification.es.html`. A `zh` file is Simplified Chinese. A request whose first language is Traditional Chinese (`zh-TW`, `zh-HK`, or `zh-Hant`) skips a `zh` file. For a built-in email, a request that lists only Traditional Chinese tags gets English, and one that also lists a bare `zh`, as many browsers send, gets Simplified Chinese.

To set the header, create the client with a locale.

```typescript
const backend = createClient(url, publishableKey, { auth: { locale: 'es' } })
```

## Read auth emails locally
<a name="backend-auth-email-local"></a>

The local backend sends every auth email to Mailpit, a mail catcher on your computer, unless the root `backend.auth` block sets `platform.customEmail.smtp`. Open the `mail.ui` address that `aws amplifygen3 local status` shows, because the port can change at each start. Mailpit loses its emails when it restarts.

If the root block sets `platform.customEmail.smtp`, the local backend sends auth emails through that server instead, with your templates. Put the server’s secrets in `.secrets/client_secrets.env`. The server must accept TLS, with a certificate from a public certificate authority. For `host`, `aws amplifygen3 local run` refuses an IP address, a host name with no dot (such as `mailpit`), and a name that ends in `.local` or `.localhost`. Run `aws amplifygen3 local run` again after you change `email-templates/`.

## SMTP settings
<a name="backend-auth-email-smtp-settings"></a>


| Setting | Value | Required | 
| --- | --- | --- | 
|  `host`  | The SMTP server’s host name | Yes | 
|  `port`  | 1 to 65535, such as `587`. Port `465` uses TLS from the start, and other ports use STARTTLS | Yes | 
|  `username`  | A `${env:NAME}` reference to a secret | Yes | 
|  `password`  | A `${env:NAME}` reference to a secret | Yes | 
|  `from`  |  `no-reply@example.com` or `Acme Notes <[no-reply@example.com](mailto:no-reply@example.com)>`  | Yes | 
|  `replyTo`  | The Reply-To address on every auth email | No | 

For template limits, see [Quotas](quotas-chapter.md).