> ## Documentation Index
> Fetch the complete documentation index at: https://docs.saasfoundation.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Email

> Configure Resend to send invitations and account emails.

SaaS Foundation uses [Resend](https://resend.com) for transactional email. The
application currently sends:

* Admin portal invitations
* Customer organization invitations
* Set-password and password-reset emails

## Configure Resend

Create a Resend account, generate an API key, and add it to your `.env` file.

```dotenv theme={null}
RESEND_API_KEY=re_...
```

The application creates the Resend client only when it needs to send an email.
If `RESEND_API_KEY` is missing, the email operation fails with a configuration
error.

<Warning>
  Treat the API key as a secret. Do not commit it to source control or expose it
  in browser code.
</Warning>

## Configure the sender

Set `EMAIL_FROM` to the address that recipients should see in the **From** field.

```dotenv theme={null}
EMAIL_FROM="notifications@your-domain.com"
```

You can include a friendly display name as well.

```dotenv theme={null}
EMAIL_FROM="Your Product <notifications@your-domain.com>"
```

If you do not set this value, SaaS Foundation falls back to
`onboarding@resend.dev`. That address is useful for initial testing but is not a
production sender.

## Test with a new Resend account

While you use the default `resend.dev` sender, Resend only allows test emails to
the email address associated with your Resend account. Attempts to send to other
recipients return an error.

This is enough to verify your local email integration before configuring DNS.
Sign in to the application with your own email address and exercise an
invitation or password flow.

## Send to other recipients

To send email to customers or teammates, add a domain you own to Resend and
verify it by adding the DNS records provided in the Resend dashboard.

Once the domain is verified:

1. Change `EMAIL_FROM` to an address on the verified domain.
2. Restart the application so it reads the updated environment value.
3. Send a test invitation to an address other than your own.

Resend does not require you to create each sender address separately. After a
domain is verified, you can send from an address at that domain. Resend
recommends choosing an address that can receive replies.

<Info>
  The domain in `EMAIL_FROM` must match the domain or subdomain you verified in
  Resend.
</Info>

See Resend's guides for [managing and verifying domains](https://resend.com/docs/dashboard/domains/introduction)
and [sender addresses](https://resend.com/docs/knowledge-base/how-do-I-create-an-email-address-or-sender-in-resend).

## Email implementation

Email code lives under `src/lib/email/`. Each email type owns its subject,
content, required inputs, and Resend call. All email functions share the client
and sender configuration from `src/lib/email/client.ts`.

```text theme={null}
src/lib/email/
├── client.ts
├── adminPortalInvitationEmail.ts
├── customerPortalInvitationEmail.ts
└── setPasswordEmail.ts
```

Better Auth invokes the password-reset and organization-invitation email
callbacks as part of its authentication workflows. SaaS Foundation owns the
email content and sends it through the shared Resend client.
