Decrypt mail for n8n, Make, Zapier and Pipedream
Automation tools such as n8n, Make, Zapier and Pipedream can receive a webhook and call the REST API, but they cannot open an encrypted message by themselves. This guide sets up a helper that does. It is one file that runs as a Cloudflare Worker in your own account. It receives the webhook, fetches the message, opens it, and posts the plain message to the URL your tool gives you.
Decryption happens in your Worker. The address key it holds opens that one address’s mail and nothing else, and it cannot sign in or create keys. The Worker also holds an API key, which can do what any API key does, including sending mail from your addresses, but cannot create keys.
You need an Operator or Scale plan (webhooks and API keys start at Operator), a free Cloudflare account, and Node.js for wrangler. Use Scale if the address is on your own domain.
What you will have
Section titled “What you will have”Mailcycle -> your Worker -> your tool's catch-hook URL webhook fetch, open plain JSON: from, subject, text, html, attachmentsYour tool receives the message as plain text, so it sees the content. Send it only to tools you choose to give that mail.
1. Export the address key
Section titled “1. Export the address key”Open the address in the web app (https://app.mailcycle.email), choose Manage, then Export address key, and select Show key. Mailcycle asks for your passcode, or your recovery phrase if you have not set a passcode, and records “Address key exported” in your account history (shown on Fleet and up). Copy the key. Export is offered in the browser only, not in the iOS and Android apps.
In code, mailcycle-sdk 0.12.0 or later returns the same key:
import { Mailcycle } from 'mailcycle-sdk';
const mc = await Mailcycle.signIn({ phrase: process.env.MAILCYCLE_PHRASE! });const { addressId, epoch, privateKey } = await mc.addresses.exportKey('ibx_k3v9x2mq7a');Treat the key like the address’s mail itself. Keep it in a secret store, never in a repository.
Every other SDK has the same call: Python, Go, Rust, Java, .NET, PHP, Ruby, Swift.
2. Create an API key
Section titled “2. Create an API key”In the app, open API, add a key on the API keys tab, and copy it. The helper uses it to fetch messages.
3. Deploy the Worker
Section titled “3. Deploy the Worker”mkdir mailcycle-decrypt && cd mailcycle-decryptcurl -O https://docs.mailcycle.email/decrypt-worker/worker.jscurl -O https://docs.mailcycle.email/decrypt-worker/wrangler.jsoncnpx wrangler secret put MAILCYCLE_API_KEYnpx wrangler secret put ADDRESS_KEYSADDRESS_KEYS is JSON that maps address ids to exported keys:
{ "ibx_k3v9x2mq7a": "your-exported-key" }Then deploy:
npx wrangler deployWrangler prints the Worker’s URL, for example https://mailcycle-decrypt.your-name.workers.dev. The free Workers plan is enough.
4. Point a webhook at it
Section titled “4. Point a webhook at it”Create the webhook in the app (API, Webhooks tab) with the Worker URL and the message.received event only. Copy the signing secret, which starts whsec_, and store it:
npx wrangler secret put WEBHOOK_SECRET5. Tell it where to send the message
Section titled “5. Tell it where to send the message”In your tool, add a catch-hook trigger (a webhook trigger in n8n and Pipedream, a custom webhook in Make, Webhooks by Zapier) and copy its URL. The URL must start with https://. A catch-hook URL works like a password for that tool, so store it as a secret:
npx wrangler secret put FORWARD_URLSend a test email to the address. Your tool receives:
{ "eventId": "evt_4k2m9x7q1b8c3v6n0z5a", "id": "msg_91be02c4a7d1", "inboxId": "ibx_k3v9x2mq7a", "keyEpoch": 0, "receivedAt": "2026-09-19T09:14:03.000Z", "from": "sender@example.com", "fromName": "", "to": ["you@example.com"], "subject": "Hello", "text": "Hi", "html": "", "attachments": []}In n8n the Webhook trigger puts this JSON under body, so a later node reads the subject as {{ $json.body.subject }}. For a trigger that listens on a local n8n, the URL still has to start with https://.
Webhooks are retried, so a message can arrive more than once. eventId is the same on each try: use it to skip a repeat.
Pull instead of push
Section titled “Pull instead of push”If your tool prefers to ask for a message after its own webhook trigger, set a PULL_TOKEN secret. The Worker then answers GET /message/<message id> with Authorization: Bearer <PULL_TOKEN> and returns the same JSON. In n8n, add an HTTP Request node after the trigger, set the URL to https://your-worker.workers.dev/message/{{ $json.body.payload.messageId }}, and give it a Header Auth credential named Authorization with the value Bearer <PULL_TOKEN>. The node’s output is the message itself, so the next node reads {{ $json.subject }}. Each attachment carries a url on the Worker that returns the opened file with the same header.
Several addresses and rotated keys
Section titled “Several addresses and rotated keys”Keep one key per address in ADDRESS_KEYS. When an address gets new keys (for example after you remove a team member with Give their addresses new keys), it moves to a new key epoch. Mail that arrives from then on is sealed under the new epoch, and earlier mail stays under the old one.
Export again after a rotation: the web app and exportKey(id) give the current epoch, and exportKey(id, 0) gives an earlier one. The other languages take the same epoch argument (export_key(id, 0) in Python and Ruby, export_key(id, Some(0)) in Rust; see the guide links above). Add each epoch you still want to read, then update the ADDRESS_KEYS secret:
{ "ibx_k3v9x2mq7a": { "0": "key-for-epoch-0", "1": "key-for-epoch-1" } }Each message records the epoch it was sealed under. An address missing from ADDRESS_KEYS is skipped without an error, and a listed address with no key for a message’s epoch returns 422.
What the Worker checks
Section titled “What the Worker checks”- The
Mailcycle-Signatureheader must match yourWEBHOOK_SECRETand be less than five minutes old. Anything else gets a 401. - A message opens only when its authentication tag verifies for that address and message.
WEBHOOK_SECRETmust be set for webhooks, andPULL_TOKENfor pull mode. Without the one a request needs, the Worker answers 500 and does nothing.- Errors never echo your secrets: anything unexpected returns
internal_error.
Stop or revoke
Section titled “Stop or revoke”- Delete the webhook in the app (API, Webhooks tab) and revoke the Worker’s API key (API, API keys tab). Delete the Worker in Cloudflare if you no longer need it.
- To stop the old key opening new mail, choose Manage, then Give this address new keys, in the web app. Mail that arrives from then on is sealed to a new key, and devices and agents holding the address receive it automatically. Export the key again to reconnect your Worker. The change is recorded as “Address given new keys” in your account history (shown on Fleet and up). From code,
mc.addresses.rotateKey(id)(mailcycle-sdk0.12.0 or later) does the same for an address that is not shared with team members. - An exported key keeps opening mail that arrived before the change, and keeps opening that address’s mail until the address gets new keys or is deleted.
Related
Section titled “Related”- Webhooks for events, retries and signatures
- Reading mail and the SDKs for opening mail in your own code
- Event stream for code that stays connected
- Walkthroughs with screenshots on the Mailcycle Blog: Run an n8n workflow on every new email and Receive email in Node-RED
© Northlab Studios Ltd, trading as Mailcycle. Registered in England and Wales, company no. 17462734. Registered office: 167-169 Great Portland Street, London W1W 5PF.