# Email (/docs/starter/modules/email)

Choose with `--email smtp` (default), `--email resend`, or `--email none`. On [a React + Vite frontend with an API](../../cli/frontend-and-api.mdx#modules-on-these-stacks), the Hono and FastAPI APIs implement every option: see [A frontend and its API](#a-frontend-and-its-api).

The app sends email through the `EmailProvider` in `apps/web/src/server/email.ts`. Server code imports `email` from `@/server/email` and calls it:

```ts title="Any server code"
import { email } from "@/server/email";

await email.send({ to, subject, text, html });
```

<Tabs items={['SMTP', 'Resend']} groupId="email" persist>
  <Tab value="SMTP">
    Set `SMTP_URL` to any SMTP server, for example `smtps://user:password@smtp.example.com:465`, and `EMAIL_FROM` to the sender, as `Name <address>` or an address. Most email providers (Resend, Postmark, Amazon SES, SendGrid, Mailgun) offer an SMTP endpoint.

    ```dotenv title="apps/web/.env.local"
    SMTP_URL=smtps://user:password@smtp.example.com:465
    EMAIL_FROM=My App <hello@example.com>
    ```

    With Docker [local services](../local-services.mdx), Mailpit catches every email: SMTP on port 1025, and the inbox at [http://localhost:8025](http://localhost:8025).
  </Tab>
  <Tab value="Resend">
    Set `RESEND_API_KEY` to a [Resend](https://resend.com) API key and `EMAIL_FROM` to a sender on a domain you verified in Resend, as `Name <address>` or an address. A key limited to sending is enough.

    ```dotenv title="apps/web/.env.local"
    RESEND_API_KEY=re_...
    EMAIL_FROM=My App <hello@example.com>
    ```
  </Tab>
</Tabs>

Without a provider configured, development prints each email to the server log, so you can open links from the terminal, and production refuses to send. `pnpm check:services` confirms that the provider accepts the settings without sending anything.

To send email in the background with retries, see [Background jobs](./jobs.mdx).

## A frontend and its API [#a-frontend-and-its-api]

With a separate API, the API sends email. Set the email variables in `apps/api/.env.local`.

- **Hono** (Starter v0.25.0 or newer): the `EmailProvider` is in `apps/api/src/server/email.ts`, and the API's code imports `email` from `@/server/email` as above.
- **FastAPI** (Starter v0.26.0 or newer): the `EmailProvider` is in `apps/api/src/clubedge_api/email.py`.

```python title="Any FastAPI code"
from clubedge_api.email import email

await email.send({"to": to, "subject": subject, "text": text, "html": html})
```

With Better Auth, which runs in the frontend's server (`apps/web/auth.server.mjs`), its confirmation and password reset emails use the same provider, so set the email variables in `apps/web/.env.local` too. See [Authentication](./auth.mdx#a-frontend-and-its-api) for the emails each provider sends.
