Skip to Content
SolidHooksSolidHooks/ Docs

Email ingestion

Give a source an email address and turn each message sent to it into a stored, routed event.

Email ingestion turns inbound email into webhooks. Give a SolidHooks source provider: "email" and it gets an address at sdhk.events. Each message sent there is stored as an event, parsed into a JSON envelope for routing, and delivered to your HTTP endpoint as JSON with the same routing, retries and replay as any webhook.

Some systems will never send a webhook. A supplier emails a notice, a bank emails an alert, an internal tool emails a nightly report. Give a source provider: "email" and anything sent to its address becomes an event that connections match, deliveries retry and retention expires like any other. Your destination receives JSON over HTTP and never speaks SMTP.

For a worked example from start to finish, see the use-case guide: Ingest webhooks via email.

How it works

  • Email is a provider, like github or generic. There is no separate flag.
  • The source view includes emailAddress, which is <maskId>@sdhk.events. It is null on every other provider.
  • Each accepted message is stored as an event with a normalised envelope as its payload.
  • The event type comes from the source's eventTypeField, or email.received if that is unset or the message does not have the field.
  • There is no verification step. Nothing signs an inbound email, so an email source takes no verifier and its verifierType is noop.

Create an email source

curl -s "$API/v1/sources" \
  -H "authorization: Bearer $SDHK_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "name": "Supplier notices",
    "provider": "email",
    "verifierConfig": {}
  }'
# → { "id": "src_...", "maskId": "Kb3xk29ZtQm7Rv1A",
#     "emailAddress": "Kb3xk29ZtQm7Rv1A@sdhk.events", ... }

Give that address to whatever sends the mail. To turn an existing source into an email source, PATCH /v1/sources/{id} with { "data": { "provider": "email" } }.

Converting a source that already has a verifier needs verifierType: "noop" in the same request, because the API will not carry a stored secret onto a source that never reads one. The same request also clears the source's idempotencyKeys and resets its eventTypeField to unset, so events are typed email.received until you set body.from or body.subject again. You can include eventTypeField in the conversion request itself.

One source does email or webhooks

A source ingests email or HTTP webhooks, never both. An HTTP POST to an email source's ingest URL returns 400 BAD_REQUEST:

{ "ok": false, "code": "BAD_REQUEST", "message": "Source ingests email and does not accept HTTP webhooks. Send email to its address instead." }

Mail and webhooks arrive on different paths, and only the email path produces an envelope. Keep a separate source for webhook traffic.

The envelope

The stored payload is a normalised envelope, so your handler does not need a mail parser.

{
  "from": "alice@example.com",
  "to": ["<maskId>@sdhk.events"],
  "cc": [],
  "subject": "Invoice #42",
  "messageId": "<abc123@mail.example.com>",
  "date": "Tue, 14 Jul 2026 09:00:00 +0000",
  "text": "plain-text body",
  "html": "<p>html body</p>",
  "spamStatus": "NotSpam",
  "bounce": false,
  "attachments": [
    { "name": "invoice.pdf", "contentType": "application/pdf", "size": 12345, "data": "<base64>" }
  ]
}

from is the From: header reduced to a bare address, so Acme Billing <billing@supplier.example> arrives as billing@supplier.example. The display name can change without the sender changing, and a per-message bounce address would never match a filter. The SMTP envelope sender is used only when a message has no From: header at all.

The event's raw body is the original JSON payload from the mail server, including any fields not shown above, with attachments[].data set to null. Attachment bytes live only in the envelope, so one large file is not stored twice. The raw body, not the envelope, is what deliveries send (see below).

What your endpoint receives

Your destination gets the event's raw body: the mail server's original JSON payload, with attachments[].data set to null. It does not get the envelope above, so field names differ (for example subject, from, plain_body and html_body), from is the full From: header rather than a bare address, and attachment contents are not included. The request is an ordinary signed delivery. New destinations sign with Standard Webhooks, so a delivery from an email source looks like this:

POST /hooks/email HTTP/1.1
Host: your-endpoint.example.com
Content-Type: application/json
webhook-id: dlv_...
webhook-timestamp: 1755300000
webhook-signature: v1,<base64>

{ "from": "Acme Billing <billing@supplier.example>", "rcpt_to": "<maskId>@sdhk.events", "subject": "Invoice #42", "plain_body": "...", "attachments": [{ "filename": "invoice.pdf", "data": null, ... }], ... }

webhook-id is the delivery id. The signature proves the request came from SolidHooks and that the body wasn't altered; it says nothing about who sent the original email (see Is inbound email verified?). Destinations created before Standard Webhooks became the default use x-solidhooks-signature and x-solidhooks-timestamp instead; check signatureScheme on the destination.

A minimal Node.js receiver that verifies the signature on the raw bytes, then reads the message:

import { createServer } from 'node:http';
import { createHmac, timingSafeEqual } from 'node:crypto';

const SECRET = process.env.SDHK_SIGNING_SECRET; // whsec_... from your destination
const TOLERANCE_SECONDS = 300;

function verify(headers, rawBody) {
  const id = headers['webhook-id'];
  const ts = headers['webhook-timestamp'];
  const sigs = headers['webhook-signature'];
  if (!id || !ts || !sigs) return false;
  if (!/^\d+$/.test(ts)) return false; // rejects NaN, empty and non-integer timestamps
  if (Math.abs(Date.now() / 1000 - Number(ts)) > TOLERANCE_SECONDS) return false;
  const key = Buffer.from(SECRET.replace(/^whsec_/, ''), 'base64');
  const signed = Buffer.concat([Buffer.from(`${id}.${ts}.`), rawBody]);
  const expected = Buffer.from(`v1,${createHmac('sha256', key).update(signed).digest('base64')}`);
  return sigs.split(' ').some((s) => {
    const b = Buffer.from(s);
    return b.length === expected.length && timingSafeEqual(b, expected);
  });
}

createServer((req, res) => {
  const chunks = [];
  req.on('data', (c) => chunks.push(c));
  req.on('end', () => {
    const raw = Buffer.concat(chunks);
    if (!verify(req.headers, raw)) { res.writeHead(401).end(); return; }
    const email = JSON.parse(raw.toString('utf8'));
    console.log(`Email from ${email.from}: ${email.subject}`);
    res.writeHead(200).end();
  });
}).listen(3000);

Return a 2xx quickly. Any other response is retried on your plan's schedule; see Retries. For the full verification rules, including secret rotation, see Verifying deliveries.

Event type and routing

An email source's eventTypeField accepts only two values:

eventTypeFieldEvent type is
body.fromThe sender's bare address, for example billing@supplier.example.
body.subjectThe subject line.

Any other path, including headers.*, is rejected with 400. These are the two single-valued fields that tell one message from another. to is always the source's own address, and cc is usually empty.

If eventTypeField is unset, or the message lacks that field (an email with no subject on a body.subject source), the type is email.received. In every case the type works in a connection's filterRules.eventTypes. Matching ignores case, so a sender that later arrives as Billing@Supplier.example still matches. Replaying an event routes with the type it was stored with.

To route on sender:

curl -s -X PATCH "$API/v1/sources/src_..." \
  -H "authorization: Bearer $SDHK_KEY" \
  -H 'content-type: application/json' \
  -d '{ "data": { "eventTypeField": "body.from" } }'

A connection can then take only that supplier with "filterRules": { "eventTypes": ["billing@supplier.example"] }.

Deduplication

Email sources deduplicate on the message's Message-ID. A repeated Message-ID returns {"ok":true,"duplicate":true} and no second event is stored. A message with no Message-ID has nothing to key on and is never deduplicated.

Setting idempotencyKeys on an email source is rejected with 400, because the key is already decided. See Idempotency and deduplication.

Size budget

Email bodies and attachments share the source's maxPayloadSizeKb, which is between 1 and 4,096 and defaults to 256. Nothing is rejected for being too big. The envelope is trimmed to fit, in this order:

  1. text is charged first. If it alone exceeds the budget it is sliced down to the budget.
  2. html is charged next. If text plus html would exceed the budget, html is dropped to null whole. It is never partially cut.
  3. Attachments are charged last. One that would exceed what is left keeps its name, contentType and size but gets "data": null and "truncated": true. Its data is omitted entirely, never partially cut.

When text is sliced or html is dropped, the envelope also carries "bodyTruncated": true.

Rotate the address

POST /v1/sources/{id}/rotate-mask rotates the email address along with the ingest URL, because the address is derived from the maskId. It needs a key scoped source: read & write.

Rotating breaks the old address

The previous address stops working as soon as you rotate. Update whatever sends the mail first, or messages sent to the old address are lost.

Common questions

Can one source receive both email and webhooks?

No. A source ingests either email or HTTP webhooks, never both. An HTTP POST to an email source's ingest URL returns 400 BAD_REQUEST with a message telling you to send email instead. Create one source for your inbound email and a separate source for webhook traffic; both can feed the same destination through their own connections.

How are attachments handled?

The stored envelope keeps attachments base64-encoded in its attachments array, with their name, content type and size. Deliveries to your endpoint carry the mail server's original payload with each attachment's data set to null, so attachment contents are not sent to your destination. Attachments share the source's maxPayloadSizeKb budget (default 256, maximum 4,096) with the body. An attachment that doesn't fit keeps its metadata but gets "data": null and "truncated": true; it is never partially cut.

What happens if the same email arrives twice?

Email sources deduplicate on the message's Message-ID. A repeat returns {"ok":true,"duplicate":true} and no second event is stored, so your endpoint isn't sent it twice. A message with no Message-ID can't be deduplicated, so if a sender omits it, make your handler idempotent too.

Can I route email by sender or subject?

Yes. Set the source's eventTypeField to body.from to type each event by the sender's bare address, or body.subject to type it by subject line. Then list the types you want in a connection's filterRules.eventTypes. Matching ignores case, and messages missing the field fall back to email.received.

Is inbound email verified?

No. Nothing signs an inbound email, so an email source has no verifier and its verifierType is noop. Treat the content as untrusted input. Routing on body.from lets you accept only the senders you expect, and the delivery to your endpoint is still signed by SolidHooks so you know it came from us.

Does the envelope include spam status?

Yes. The envelope carries a spamStatus field (for example "NotSpam") and a bounce boolean alongside the addresses, subject, bodies and attachments. The delivered payload is the mail server's original JSON, where the same information appears as spam_status and bounce.

Next steps