# Send alerts through your own email provider

Source: https://help.ruuster.com/idx/alerts-send-it-yourself

> Receive each alert as a ready-to-send object by webhook or from the queue, send it through Resend, SendGrid, Postmark, Mailgun or Amazon SES, report the result, and pass your provider's events back.

You send every alert through your own email provider, so it comes from your own domain and your
provider's reputation. We hand you a **delivery object** with everything the email needs.

## The delivery object

```json
{
  "deliveryId": "del_7Kq2Vm9Xp4Lt8Z",
  "kind": "price_drop",
  "cadence": "instant",
  "scheduledFor": "2026-11-23T15:05:00.000Z",
  "subscriber": { "id": "buy_K2v9QmT4xLp8", "email": "jamie@example.com", "firstName": "Jamie", "lastName": "Lee", "externalId": "fub-123" },
  "agent": { "id": "agt_Q8m2Vx7Lp4Tz", "name": "Dana Reyes", "email": "dana@example-homes.com", "phone": "512-555-0101", "photoUrl": null },
  "from": { "name": "Dana Reyes" },
  "replyTo": "dana@example-homes.com",
  "subject": "Price reduced: 1204 Oak Ln",
  "html": null,
  "text": "Hi Jamie, ...",
  "listings": [
    { "listingId": "5b7e2d94-1c63-4a8f-b5e0-9d3c7a2f1e86", "kind": "price_drop", "url": "https://www.example-homes.com/homes/5b7e2d94-1c63-4a8f-b5e0-9d3c7a2f1e86?token=...", "price": 589000, "previousPrice": 610000, "priceChange": -21000, "address": "1204 Oak Ln", "city": "Austin", "beds": 3, "baths": 2, "attribution": "Listing courtesy of Example Realty" }
  ],
  "moreCount": 0,
  "links": { "search": "...", "adjust": "...", "unsubscribe": "...", "preferences": "..." },
  "headers": { "List-Unsubscribe": "<https://...>", "List-Unsubscribe-Post": "List-Unsubscribe=One-Click" },
  "postalAddress": "100 Congress Ave, Austin, TX 78701"
}
```

`kind` is `new_listing`, `price_drop`, `back_on_market`, `sold`, `welcome` or `digest`. `text` is a
plain body you can send as it is; build your HTML from `listings` and `links` in your own template.
Always copy `headers` onto the email: they give mail apps a one-click unsubscribe. Show each
listing's `attribution` where it is present, and your `postalAddress` in the footer.

## Two ways to receive it

**By webhook (recommended).** Set `webhookUrl` in your alert settings. Each new delivery arrives as a
signed `delivery.ready` event with the object in `data.delivery`. See
[Alerts webhooks](/idx/alerts-webhooks).

**From the queue.** Poll `GET /v1/deliveries` (pending by default) from a scheduled function, every
few minutes. Call `POST /v1/deliveries/{deliveryId}/ack` before you send, so a second worker skips
it.

Either way, a delivery with no result after 72 hours expires and must not be sent.

## A send route (Resend)

```js
// app/api/alerts-webhook/route.js (Next.js); verifySignature is on the webhooks page
import { Resend } from "resend";
const resend = new Resend(process.env.RESEND_API_KEY);
const API = "https://idx.ruuster.com/v1";
const auth = { Authorization: `Bearer ${process.env.IDX_SECRET_KEY}`, "Content-Type": "application/json" };

export async function POST(req) {
  const raw = await req.text();
  if (!verifySignature(raw, req.headers.get("Ruuster-Signature"), process.env.RUUSTER_ALERTS_WEBHOOK_SECRET)) return new Response("bad signature", { status: 401 });
  const event = JSON.parse(raw);
  if (event.kind !== "delivery.ready") return Response.json({ ok: true });
  const d = event.data.delivery;
  const sent = await resend.emails.send({
    from: `${d.from.name} <alerts@mail.example-homes.com>`,
    to: d.subscriber.email,
    replyTo: d.replyTo ?? undefined,
    subject: d.subject,
    text: d.text,
    headers: Object.fromEntries(Object.entries(d.headers).filter(([, v]) => v)),
  });
  await fetch(`${API}/deliveries/${d.deliveryId}/result`, {
    method: "POST",
    headers: auth,
    body: JSON.stringify(sent.error ? { status: "failed", reason: sent.error.message } : { status: "sent", providerMessageId: sent.data.id }),
  });
  return Response.json({ ok: true });
}
```

The other providers take the same fields under their own names:

| Provider | From | Reply-To | Headers | Message id |
|---|---|---|---|---|
| SendGrid | `from: { email, name }` | `replyTo` | `headers` | `x-message-id` response header |
| Postmark | `From` | `ReplyTo` | `Headers: [{ Name, Value }]` | `MessageID` |
| Mailgun | `from` | `h:Reply-To` | `h:List-Unsubscribe`, `h:List-Unsubscribe-Post` | `id` |
| Amazon SES | `FromEmailAddress` | `ReplyToAddresses` | `Headers` in `Content.Simple` | `MessageId` |

## Report the result

`POST /v1/deliveries/{deliveryId}/result` with `status` `sent`, `failed` or `suppressed` (your
provider refused the address) and the provider's message id. Repeating the same result is safe.

## Pass your provider's events back (optional)

Forward your provider's events with `POST /v1/deliveries/{deliveryId}/events`: `delivered`,
`opened`, `clicked`, `bounced`, `complained` and `unsubscribed`, each with your provider's event `id`
so a replay is ignored. A bounce, a spam complaint or an unsubscribe stops that buyer's alerts and
keeps their email off every later alert. An open with a click within four seconds is counted as a
mail scanner, not a person.

## Credits

Alerts you send yourself use none of your email credits; your provider bills its own sends.
