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

# Email Channel

> Send emails using Resend and track delivery rates

The `EMAIL` channel routes transactional email dispatches to Resend using your encrypted tenant credentials.

## Resend Gateway Configuration

Email configurations require two pieces of data in the Providers tab:

* **API Key:** A secret token generated under your Resend account.
* **Metadata Config:**
  * `fromEmail`: The email address showing in the recipient's "From" field (e.g. `support@yourdomain.com`).
  * `fromName`: The human-readable name showing in the recipient's "From" field (e.g. `Acme Support`).

***

## Sandbox Mode Restrictions

If you sign up for a free Resend account and choose not to verify a domain immediately, your account operates in a **Sandbox Mode** under these strict limitations:

* **Sender Address:** Locked to `onboarding@resend.dev`. You cannot send emails from custom addresses.
* **Recipient Domain:** You can **only** deliver emails to the specific email address that signed up for the Resend account. Any other target address yields a rejection error.

To deliver notifications to arbitrary customer inbox addresses, you must verify your custom domain:

<Steps>
  <Step title="Verify custom domain in Resend">
    Go to Resend -> **Domains** -> **Add Domain** and follow the instructions to publish DNS records.
  </Step>

  <Step title="Update Provider on Notifyflow">
    Update your `fromEmail` config in the Provider Modal to use your verified domain address (e.g. `no-reply@yourdomain.com`).
  </Step>
</Steps>

***

## Delivery Attempts and Errors

The worker records all delivery metadata in the `delivery_attempts` table. If Resend rejects the API call, the error message is stored and visible inside the **Notifications** logs. Common failure reasons include:

* `401 Unauthorized`: Your API Key is invalid or has expired/been rotated on Resend.
* `422 Unprocessable Entity`: The recipient address has bounced repeatedly or is on Resend's suppressions list.
* `422 validation`: The sender email domain is not verified.

***

## Developer Implementation

Developers trigger email notifications by making an authenticated HTTP `POST` call to `/api/v1/notify`. You can request delivery using either a pre-configured template or a raw text payload.

### Method 1: Using a Template

```typescript theme={null}
const response = await fetch("https://notifyflow-api.onrender.com/api/v1/notify", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.NOTIFYFLOW_API_KEY // Kept server-side
  },
  body: JSON.stringify({
    channel: "EMAIL",
    recipient: "customer@example.com",
    templateName: "order_confirmed", // Name of template in your dashboard
    data: {
      customerName: "Alex",
      orderId: "ORD-9876",
      amount: 2999
    },
    priority: "HIGH"
  })
});

const data = await response.json();
console.log("Ingested Notification ID:", data.notificationId);
```

### Method 2: Using Raw Subject and Body

```typescript theme={null}
const response = await fetch("https://notifyflow-api.onrender.com/api/v1/notify", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.NOTIFYFLOW_API_KEY
  },
  body: JSON.stringify({
    channel: "EMAIL",
    recipient: "customer@example.com",
    rawSubject: "System Alert",
    rawBody: "Your server usage has exceeded 90%. Please review dashboard.",
    priority: "DEFAULT"
  })
});
```
