# Email Configuration

> Set up email for a self-hosted LearnHouse instance with Resend or any SMTP server, and set the sender address and display name for outgoing mail.

LearnHouse supports two email providers for transactional email delivery: **Resend** and **SMTP**. Email is used for user invitations, password resets, and system notifications.

## Choosing a Provider

Set the email provider in your `.env` file using the `LEARNHOUSE_EMAIL_PROVIDER` variable:

```env
LEARNHOUSE_EMAIL_PROVIDER=resend   # or "smtp"
```

## Option 1: Resend

[Resend](https://resend.com) is a developer-friendly email API service.

```env
LEARNHOUSE_EMAIL_PROVIDER=resend
LEARNHOUSE_RESEND_API_KEY=re_your-resend-api-key
LEARNHOUSE_SYSTEM_EMAIL_ADDRESS=noreply@example.com
```

### Getting a Resend API Key

1. Create an account at [resend.com](https://resend.com)
2. Add and verify your sending domain
3. Generate an API key from the Resend dashboard
4. Copy the API key into your `.env` file

## Option 2: SMTP

You can use any SMTP server, including services like Amazon SES, Mailgun, or your own mail server.

```env
LEARNHOUSE_EMAIL_PROVIDER=smtp
LEARNHOUSE_SMTP_HOST=smtp.example.com
LEARNHOUSE_SMTP_PORT=587
LEARNHOUSE_SMTP_USERNAME=user@example.com
LEARNHOUSE_SMTP_PASSWORD=your-smtp-password
LEARNHOUSE_SMTP_USE_TLS=true
LEARNHOUSE_SYSTEM_EMAIL_ADDRESS=noreply@example.com
```

### SMTP Variables

| Variable | Description | Default |
|---|---|---|
| `LEARNHOUSE_SMTP_HOST` | SMTP server hostname | None |
| `LEARNHOUSE_SMTP_PORT` | SMTP server port | `587` |
| `LEARNHOUSE_SMTP_USERNAME` | SMTP authentication username | None |
| `LEARNHOUSE_SMTP_PASSWORD` | SMTP authentication password | None |
| `LEARNHOUSE_SMTP_USE_TLS` | Enable TLS encryption | `true` |

## Applying Changes

After updating your email configuration, apply it (this recreates the containers whose configuration changed):

```bash
npx learnhouse start
```

You can also set these variables with `npx learnhouse env`, which offers to restart services when you are done.

## System Email Address

The `LEARNHOUSE_SYSTEM_EMAIL_ADDRESS` is the "from" address used for all outgoing emails. When using Resend, this address must belong to a domain that is verified in your Resend account. When using SMTP, ensure the address is permitted by your SMTP server.

## Sender Display Name

Emails arrive as `LearnHouse <noreply@example.com>`. `LEARNHOUSE_SYSTEM_EMAIL_SENDER_NAME` replaces the `LearnHouse` part for the whole deployment:

```env
LEARNHOUSE_SYSTEM_EMAIL_SENDER_NAME=Acme Academy
```

It defaults to `LearnHouse`, so leaving it unset changes nothing.

### Per-organization override

Organization administrators can set their own name under **Dashboard → Organization → Settings → General → Email Sender Name**. Mail sent for that organization (invitations, password resets, verification, role changes, welcome mail, lifecycle nudges) then carries the organization's name instead of the deployment default. Mail that is not about a single organization (platform password resets, org-less signups, account deletion, magic-login links) always uses the deployment default.

> Only the display **name** is configurable, never the sending **address**. The address stays `LEARNHOUSE_SYSTEM_EMAIL_ADDRESS`, which is the domain carrying your verified SPF and DKIM records. An organization sending from an address on some other domain would fail DKIM alignment on every message, and on a shared sending domain that damages deliverability for every other tenant too.

Names are sanitized before they reach the header: control characters and line breaks are removed, whitespace runs are collapsed, and the result is capped at 64 characters. A carriage return or newline in a header value is header injection, so this is enforced on write and again on send.

> If email is not configured, features like user invitations and password resets will not work. Users can still be created manually by an administrator.

## What Emails Are Sent

LearnHouse sends the following types of email:

- **User invitations**: when an admin invites a user to join the platform or an organization
- **Password resets**: when a user requests a password reset
- **System notifications**: important system-level notifications
