# Set Up Email for Invitations

Source: https://agenta.ai/docs/self-host/access-control/set-up-email

Agenta sends email for two things: invitations to an organization, and one-time sign-in codes. A self-hosted instance sends no email until you configure SMTP or SendGrid. This page shows how to do both, and how invitations work without email.

## Invitations without email

If neither SMTP nor SendGrid is configured, invitations still work, but nobody receives an email. Share the link by hand:

1. Go to **Settings > Members** and invite the user's email.
2. Agenta shows an **Invited user link** dialog. Select **Copy**.
3. Send the link to the user through any channel. They open it, sign in with the invited email, and join the organization.

An invitation link expires after 7 days. To get a new link for a pending invitation, open the member's menu in **Settings > Members** and select **Resend invitation**. Agenta shows the new link in the same dialog.

## Choose SMTP or SendGrid

Agenta uses SMTP when `SMTP_HOST`, `SMTP_PORT`, and `SMTP_FROM_EMAIL` are all set. Otherwise it uses SendGrid when `SENDGRID_API_KEY` and `SENDGRID_FROM_EMAIL` are both set. If you set both, SMTP wins.

:::warning Email sign-in changes to one-time codes
When email delivery is configured, email sign-in stops asking for a password. Users enter their email and receive a one-time code instead. Without email delivery, users sign in with email and password. To turn email sign-in off and keep only SSO, see [Configure SSO](https://agenta.ai/docs/self-host/guides/configure-sso.md).
:::

## Docker Compose

### SMTP

Add these lines to your env file (for example `hosting/docker-compose/oss/.env.oss.gh`):

```bash
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USERNAME=agenta@example.com
SMTP_PASSWORD=your-smtp-password
SMTP_FROM_EMAIL=agenta@example.com
# STARTTLS on port 587 (default true). For implicit TLS on port 465, set SMTP_USE_TLS=false and SMTP_USE_SSL=true.
SMTP_USE_TLS=true
```

Set `SMTP_USERNAME` and `SMTP_PASSWORD` together, or leave both empty for a relay that needs no login.

To test with [Mailpit](https://mailpit.axllent.org/) running on the same host, use:

```bash
SMTP_HOST=host.docker.internal
SMTP_PORT=1025
SMTP_FROM_EMAIL=agenta@example.com
SMTP_USE_TLS=false
```

### SendGrid

Add these lines to your env file:

```bash
SENDGRID_API_KEY=SG.your-api-key
SENDGRID_FROM_EMAIL=agenta@example.com
```

The sender address must be a verified sender in your SendGrid account.

### Apply the change

The API sends the email, and the web container reads the same variables to decide which sign-in form to show. Recreate both:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml \
  --env-file hosting/docker-compose/oss/.env.oss.gh \
  --profile with-traefik up -d --force-recreate api web-mobile
```

Use the same `-f`, `--env-file`, and `--profile` flags you used to start the stack. The containers read the file named by `ENV_FILE`, which defaults to `.env.oss.gh`. If your env file has another name, set `ENV_FILE` to its path before you run the command, or recreate the containers with `run.sh` and its `--env-file` flag.

## Kubernetes

### SMTP

Add an `smtp` block to your values file:

```yaml
smtp:
  host: smtp.example.com
  port: 587
  username: agenta@example.com
  password: your-smtp-password
  fromEmail: agenta@example.com
  useTls: true
```

The chart stores `smtp.password` in its Secret. If you use `secrets.existingSecret`, leave `smtp.password` out of the values file and add an `SMTP_PASSWORD` key to your Secret instead.

### SendGrid

```yaml
sendgrid:
  apiKey: SG.your-api-key
  fromEmail: agenta@example.com
```

If you use `secrets.existingSecret`, add a `SENDGRID_API_KEY` key to your Secret, and keep `sendgrid.apiKey` set in the values file. The chart passes the key to the pods only when `sendgrid.apiKey` is set.

### Apply the change

Run `helm upgrade` with your values file. Adding the `smtp` or `sendgrid` block changes the pod environment, so the upgrade rolls out new pods.

The chart does not restart pods when only a Secret value changes. If you later change only the password or the API key, restart the API deployment with `kubectl rollout restart`.

## Check that email works

Invite a test address from **Settings > Members**. If no email arrives, read the API logs:

| Log line | Meaning |
|---|---|
| `[EMAIL] Disabled - would send ...` | The API does not see a complete SMTP or SendGrid configuration. Check the variable names and recreate the API container. |
| `Failed to send SMTP email` | SMTP is configured, but the server rejected the connection or the login. The lines after it show the error. |
| `Failed to send SendGrid email` | SendGrid is configured, but the request failed. Check the API key and the verified sender. |

For every email variable and its Helm values path, see the [configuration reference](https://agenta.ai/docs/self-host/configuration.md#smtp).
