Letterbox.Ingress.Relay (Letterbox v0.1.0-rc.0)

Copy Markdown View Source

Raw emails, posted as they are by whatever has them: a mail server's pipe (Postfix, Exim), a Cloudflare Email Worker, a script.

config :letterbox, ingresses: [relay: [token: "a long random token"]]

A request is a POST to its route (/inbound/webhooks/relay, as mix letterbox.install writes it) with the email as its body (Content-Type: message/rfc822), and the token as a bearer (Authorization: Bearer <token>) or as the password of basic auth (as Action Mailbox's relay takes it). Two headers help:

  • X-Letterbox-Recipients - the envelope's recipients, separated by commas: the addresses the mail server took it for.
  • X-Letterbox-Id - an id of the email's, to take it once only when it is posted twice.

From Postfix, in master.cf:

letterbox unix - n n - - pipe
  flags=Rq user=mail argv=/usr/bin/curl --fail --data-binary @-
    -H Content-Type:message/rfc822 -H Authorization:Bearer\ <token>
    -H X-Letterbox-Recipients:${recipient}
    https://example.com/inbound/webhooks/relay

From a Cloudflare Email Worker:

export default {
  async email(message, env) {
    await fetch("https://example.com/inbound/webhooks/relay", {
      method: "POST",
      body: message.raw,
      headers: {
        "content-type": "message/rfc822",
        authorization: `Bearer ${env.LETTERBOX_TOKEN}`,
        "x-letterbox-recipients": message.to
      }
    });
  }
};