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

# Email Setup via Resend

> Configure Resend for local email testing and production sending from your verified domain.

AspFox sends transactional email via [Resend](https://resend.com). All 12 email templates are already written — you configure the API key and sending address.

## Local development

### Create a Resend account and API key

1. Sign up at [resend.com](https://resend.com)
2. Go to **API Keys** → **Create API Key**
3. Add to `.env`: `RESEND_API_KEY=re_…`

### Use the shared onboarding address

Without a verified domain, use `onboarding@resend.dev` as your FROM address. Resend allows all accounts to send from this address for testing.

```bash theme={null}
EMAIL_FROM_ADDRESS=onboarding@resend.dev
EMAIL_FROM_NAME=Acme
```

Every email you send appears in the **Emails** section of the Resend dashboard with delivery status, the full rendered HTML, and bounce/open tracking.

<Note>
  With `onboarding@resend.dev`, emails can only be sent to the email address that owns the Resend account. To send to other addresses during development, you need to verify a domain.
</Note>

## Production

### Verify your sending domain

1. Resend Dashboard → **Domains** → **Add Domain**
2. Enter your domain (e.g., `yourdomain.com`)
3. Add the DNS records Resend provides (DKIM, SPF, DMARC)
4. Wait for verification (usually minutes; up to 24 hours)

### Update your sending address

```bash theme={null}
EMAIL_FROM_ADDRESS=noreply@yourdomain.com
EMAIL_FROM_NAME=Acme
```

## Email templates

AspFox includes 12 pre-built HTML templates. All use inline styles for email client compatibility.

| Template                | When it is sent                                         |
| ----------------------- | ------------------------------------------------------- |
| `Welcome`               | After email verification is complete                    |
| `EmailVerification`     | After registration — contains the verification link     |
| `PasswordReset`         | After requesting a password reset                       |
| `MagicLink`             | After requesting a magic link login                     |
| `PasswordChanged`       | Confirmation after a successful password change         |
| `TenantInvitation`      | When a user is invited to a workspace                   |
| `TrialExpiry7Day`       | 7 days before trial expiration (sent by TrialExpiryJob) |
| `TrialExpiry1Day`       | 1 day before trial expiration (sent by TrialExpiryJob)  |
| `PaymentFailed`         | When `invoice.payment_failed` webhook is received       |
| `PaymentRecovered`      | When payment succeeds after a past-due period           |
| `CancellationScheduled` | When subscription is set to cancel at period end        |
| `CancellationConfirmed` | When subscription is fully canceled                     |

Template classes live in `src/YourProject.Infrastructure/Email/Templates/`. Each extends `EmailTemplateBase` and implements `RenderContent()` to return the email body HTML.

## Testing email rendering locally

To preview a template without sending it:

```csharp theme={null}
// Temporary code in a test or scratch endpoint:
var template = new EmailVerificationTemplate(
    userName: "Jane",
    verificationUrl: "http://localhost:5173/verify-email?token=test"
);
var html = template.Render();
await File.WriteAllTextAsync("/tmp/email-preview.html", html);
```

Then open `/tmp/email-preview.html` in a browser to see the rendered template. Delete the temporary code afterward.
