Skip to content

http-filter

Once an email is received (DATA), the http-filter filter sends a CloudEvent describing it to an HTTP endpoint, as JSON. A 2xx answer accepts the email for the flow; any other status refuses it.

When the decision needs your own logic: the content of the email, a list of allowed senders kept elsewhere, a quota per user. The endpoint sees the sender, the recipients, the subject, the text and HTML bodies (truncated to 8192 characters), the attachment names and sizes, and the client details, including the authenticated username.

  • It decides after DATA, so recipients wait until then: a flow whose only filter is http-filter answers 250 to every RCPT TO, and the email is refused with 450 if the endpoint refuses it and no other flow takes it. See routing.
  • A 2xx answer makes the flow take every recipient it has not refused. Combine it with a whitelist on to (AND) to refuse unknown recipients at RCPT TO first.
  • With allowAnyUser: true, the filter also accepts any AUTH command, whatever the credentials, and leaves the decision to the endpoint, which finds the username in data.server.username.
  • Requests can be signed with an HMAC, as for http-auth.
OptionTypeDescription
allowAnyUserboolean
default false

Accept any SMTP authentication, whatever the username and password, leaving the decision to the endpoint (the CloudEvent carries the username in data.server.username)

hmacobject

Sign the requests with an HMAC so the endpoint can authenticate them

The request carries the time in milliseconds in the X-SMTP-RELAY-TIME header and the hex HMAC of <url>\n<method>\n<time> (followed by \n<body> when there is a body) in the header header

hmac.algostring
default "sha256"

Hash algorithm of the HMAC, any algorithm of node crypto.getHashes()

hmac.headerstring
default "X-SMTP-RELAY"

Name of the header carrying the signature

hmac.secretrequiredstring

Secret key of the HMAC

method"PUT" | "POST"
default "POST"

HTTP method of the request

namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

typerequired"http-filter"

Type of the component

urlrequiredstring

URL receiving the CloudEvent describing the email

http-filter.jsonc
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"checked": {
"filters": [
{ "type": "whitelist", "to": ["regexp:.*@mydomain.com"] },
{
"type": "http-filter",
"url": "https://filter.example.com/smtp/email",
"hmac": { "secret": "change-me" }
}
],
"outputs": [{ "type": "file", "path": "./received_emails/" }]
}
},
"bind": "0.0.0.0",
"options": { "authOptional": true }
}

The same CloudEvent is sent by http-filter and published by the pubsub option of the aws and gcp outputs. Its type is com.loopingz.smtp-relay.v2, its source the local address of the server, its subject the Message-ID of the email, and its time the time the connection was opened.

{
"id": "53562c7c-5010-4ba7-af2e-337b0a34aabc",
"time": "2026-11-30T09:15:02.117Z",
"type": "com.loopingz.smtp-relay.v2",
"source": "172.17.0.2",
"specversion": "1.0",
"subject": "<4f1c2e@mail.example.com>",
"data": {
"email": {
"from": {
"value": [{ "address": "alice@example.com", "name": "Alice" }],
"html": "…",
"text": "\"Alice\" <alice@example.com>"
},
"attachments": [{ "filename": "invoice.pdf", "size": 48213 }],
"subject": "Invoice 2026-11",
"to": {
"value": [{ "address": "billing@mydomain.com", "name": "" }],
"html": "…",
"text": "billing@mydomain.com"
},
"text": "Hello,\nplease find the invoice attached.\n",
"html": "<p>Hello,</p>…"
},
"server": {
"clientHostname": "app.example.com",
"remoteAddress": "10.0.3.17",
"remotePort": 51544,
"hostNameAppearAs": "app.example.com",
"id": "3ieb2d4f6ng7jgor",
"secure": true,
"transmissionType": "ESMTPSA",
"username": "app"
}
}
}
  • email.from, email.to, email.cc and email.bcc are address objects parsed from the headers. When the email has no From or To header, from is the envelope sender and to the envelope recipients. When an http-filter ran, the field is set once for the whole email, so the outputs’ CloudEvents list every envelope recipient, not only those of their flow; otherwise an output’s CloudEvent lists its flow’s recipients.
  • email.priority is the Priority header, when present.
  • subject, text, html, the attachment file names and server.clientHostname are truncated: to 8192 characters by default, to pubsub.truncate in the outputs.
  • Fields without a value (no HTML body, no authenticated user…) are left out.