How to Run an n8n Workflow on Every New Email

Start an n8n workflow on every new email with a Webhook trigger. A small helper opens each Mailcycle message and sends n8n the plain from, subject and text.

By · · 14 min read

The n8n Webhook trigger expressions that read from, subject, text and receivedAt from the opened Mailcycle message

A lot of n8n workflows begin with a message: an order confirmation to log, a support request to route, a form notification to copy into a sheet, a reply to match with a record. The usual route is an email trigger that polls a mailbox over IMAP. It works, but it ties the workflow to a mailbox password, a polling interval and a folder that other things also write to.

There is a simpler shape. Give the workflow an address of its own, and let each new email start one execution. In this tutorial you’ll set that up with a Mailcycle address, a webhook, and the Mailcycle decrypt helper, a single small file you run in your own Cloudflare account. Mail is encrypted the moment it arrives. The helper opens each message with the key for that one address and hands n8n the plain message: sender, subject, text, HTML and attachments.

Everything below was run on n8n 2.35.7 against real messages on our test account, and the screenshots are from that run; the section on running n8n on your own machine says which step was simulated.

What you’ll build

Two small workflows. The first is push mode: a Webhook trigger receives the opened message and an Edit Fields node keeps the four fields you care about. The second is pull mode: the trigger receives only a message id, and an HTTP Request node asks the helper for the opened message.

In push mode, this is what the Webhook trigger holds after one new email. The helper added eventId; everything else is the message:

{
  "eventId": "evt_8d8b5d1beda8eda94bd0",
  "id": "msg_K17ipiK2DvRV",
  "inboxId": "ibx_yuhto9gmv0je",
  "keyEpoch": 0,
  "receivedAt": "2026-11-27T14:44:04.666Z",
  "from": "hello@northlabstudios.com",
  "fromName": "Northlab Studios",
  "to": [],
  "subject": "Hello from Mailcycle",
  "text": "Hello, this message is arriving on a phone without Google Play.\n",
  "html": "...",
  "attachments": []
}

The html field carries the sender’s whole HTML body, which is long, so the example shortens it.

Flow: a sender writes to the address, Mailcycle encrypts the mail on arrival and sends a webhook, the helper in your Cloudflare account opens the message, and the n8n Webhook trigger starts the workflow
Each new email starts one n8n execution with the opened message.

How the helper and n8n fit together

n8n can receive a webhook and call the REST API. What it needs in between is something that opens the encrypted message. The decrypt helper is that piece: one file, worker.js, that runs as a Cloudflare Worker in your account.

The path for one email:

  1. A sender writes to your Mailcycle address. The message is encrypted on arrival.
  2. Mailcycle sends a signed message.received event to the helper’s URL. It carries the message id and the address id, and no content.
  3. The helper checks the signature, fetches the message with your API key, opens it with the address key and POSTs the plain JSON to the FORWARD_URL you set.
  4. n8n’s Webhook trigger receives that JSON and starts the workflow.

Your n8n then sees the content of the message, as plain text, so give this address only to workflows you want to have that mail. A dedicated address for the workflow keeps the scope to exactly that.

Prerequisites

  • An Operator or Scale plan. Webhooks and API keys start at Operator. Choose Scale when the address is on your own domain.
  • n8n with a public https:// address. Cloud, or self-hosted behind a reverse proxy, both work. For a local n8n, see the section on running it locally below.
  • A free Cloudflare account and Node.js, for wrangler, which deploys the helper. The free Workers plan is enough.
  • An address on your Mailcycle account to receive the mail.

Step 1: Export the address key

The helper opens mail with the key for the address, so start by exporting it. In the web app (https://app.mailcycle.email):

  1. Open the address and choose Manage.
  2. Choose Export address key, then Show key.
  3. Enter your passcode, or your recovery phrase if you have not set a passcode.
  4. Copy the key.

Mailcycle records “Address key exported” in your account history, which is shown on Fleet and up. Export is offered in the browser, so do this step on the web app.

If you prefer code, the TypeScript SDK returns the same key. It needs mailcycle-sdk 0.12.0 or later:

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');

Keep the key in a secret store, never in a repository. It opens that one address’s mail and nothing else.

Step 2: Create an API key

The helper fetches messages with an API key. In the app, open API, choose the API keys tab, add a key and copy it. Name it after the job, for example “n8n helper”, so you can find and revoke it later.

Step 3: Deploy the helper

Create a folder and download the two files from the docs site:

mkdir mailcycle-decrypt && cd mailcycle-decrypt
curl -O https://docs.mailcycle.email/decrypt-worker/worker.js
curl -O https://docs.mailcycle.email/decrypt-worker/wrangler.jsonc
npx wrangler secret put MAILCYCLE_API_KEY
npx wrangler secret put ADDRESS_KEYS

wrangler asks for each value. ADDRESS_KEYS is JSON that maps address ids to the exported keys:

{ "ibx_k3v9x2mq7a": "your-exported-key" }

Then deploy:

npx wrangler deploy

Wrangler prints the helper’s URL, for example https://mailcycle-decrypt.your-name.workers.dev. Keep it for step 5.

Step 4: Add the Webhook trigger in n8n

In n8n, create a workflow and add a Webhook node. Set:

Field Value
HTTP Method POST
Path mailcycle-mail
Respond Immediately

n8n shows two URLs: a test URL (/webhook-test/mailcycle-mail) that listens once while you press Execute workflow, and a production URL (/webhook/mailcycle-mail) that works once the workflow is published. Copy the production URL, which starts https://, and give it to the helper:

npx wrangler secret put FORWARD_URL

Paste the URL when asked. A catch-hook URL works like a password for the workflow, so a secret is the right place for it, and the helper only forwards to an https:// address.

The n8n Webhook trigger named Mailcycle mail, set to POST with the path mailcycle-mail, showing the message fields in its output
The Webhook trigger after one delivery: headers, then the message fields under body.

Step 5: Point a Mailcycle webhook at the helper

In the app, open API, then the Webhooks tab, and add a webhook:

  1. Paste the helper’s URL from step 3.
  2. Subscribe to message.received only.
  3. Copy the signing secret, which starts whsec_.

Store the secret in the helper:

npx wrangler secret put WEBHOOK_SECRET

From now on every delivery is checked. The Mailcycle-Signature header has to match your secret and be less than five minutes old, or the helper answers 401 and forwards nothing. In the run for this tutorial, a delivery signed with the wrong secret came back as:

-> 401 {"error":"bad_signature"}

and the correctly signed one as:

-> 200 {"ok":true}

Step 6: Send a test email and read the fields

Send a message to the address from any mail account. Within a moment the Webhook trigger has an execution. Open the workflow’s Executions tab to see it. A production webhook call does not animate the canvas, so the Executions tab is where the run shows.

The n8n Executions tab for the push workflow: Succeeded in 40ms, with the Mailcycle mail and Pick fields nodes both showing a green check
One new email, one execution: the run took 40 ms.

The Webhook trigger keeps the JSON it receives under body, next to headers, params and query. That is the detail that trips most first workflows: the subject is not {{ $json.subject }} but {{ $json.body.subject }}.

Step 7: Build the workflow after the trigger

Add an Edit Fields (Set) node after the trigger, in manual mapping mode, and add four string fields:

Field Expression
from {{ $json.body.from }}
subject {{ $json.body.subject }}
text {{ $json.body.text }}
receivedAt {{ $json.body.receivedAt }}

The output is one clean item per email, and everything after it reads the short names. The html field is large because it carries the sender’s inline CSS, so leaving it out here keeps the data that moves through the rest of the workflow small.

The n8n Edit Fields node named Pick fields with the expressions $json.body.from, $json.body.subject, $json.body.text and $json.body.receivedAt, and the resulting row in its output
Edit Fields turns the delivery into four short fields.

You can import the same two nodes instead of building them. This is the push workflow as n8n exports it:

{
  "name": "Mailcycle mail via decrypt helper (push)",
  "nodes": [
    {
      "parameters": { "httpMethod": "POST", "path": "mailcycle-mail", "options": {} },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [0, 0],
      "name": "Mailcycle mail"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "name": "from", "value": "={{ $json.body.from }}", "type": "string" },
            { "name": "subject", "value": "={{ $json.body.subject }}", "type": "string" },
            { "name": "text", "value": "={{ $json.body.text }}", "type": "string" },
            { "name": "receivedAt", "value": "={{ $json.body.receivedAt }}", "type": "string" }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [240, 0],
      "name": "Pick fields"
    }
  ],
  "connections": {
    "Mailcycle mail": { "main": [[{ "node": "Pick fields", "type": "main", "index": 0 }]] }
  }
}

Paste it into a new workflow with Import from file or by pasting the JSON onto the canvas, then publish.

Route on the sender or the subject

From here the workflow is ordinary n8n. A few shapes that fit mail well:

  • IF or Switch on subject or from. Send invoices down one branch and support requests down another. Match on a start of the subject such as Order #, or on the sender’s domain.
  • Code node for a value in the text. A short expression pulls an order number, a code or a link out of text, and the next node uses it.
  • Append to Google Sheets, create a Notion page or post to a chat channel. The four short fields map directly to columns or message parts.
  • Wait for a human. An approval step can use the mail’s subject and from as the context the person sees.

Keep every action one your own workflow is allowed to take for the mail you receive. Mailcycle’s acceptable use policy covers the rest.

Attachments

Every message carries an attachments list. Each entry has an index, filename, mimeType and size. When the helper has a PULL_TOKEN set (the next section), each entry also has a url on the helper that returns the opened file.

To save a file in n8n, add an HTTP Request node after the trigger, loop over attachments with a Split Out node first if there is more than one, set the URL to the entry’s url, set the response format to File, and give it the same Header Auth credential as in pull mode. The node’s binary output is the file itself, ready for a Google Drive, S3 or Read PDF node.

The test account for this run had no attachments, so the screenshots here show the text fields only. The attachments shape comes from the helper’s source and the decrypt helper guide.

Pull mode: the trigger sends an id, n8n asks for the message

Push mode sends the whole message to n8n. Pull mode keeps the trigger small: it receives a message id, and n8n asks the helper for the opened message when it needs it. That suits a workflow that only sometimes reads the content, or one that already has its own trigger.

Set a PULL_TOKEN secret on the helper:

npx wrangler secret put PULL_TOKEN

The helper then answers GET /message/<message id> with the opened message as JSON. The token goes in the Authorization header. This is the real request and its answer from the run, without the long html field:

curl -s -H "Authorization: Bearer $PULL_TOKEN" https://mailcycle-decrypt.your-name.workers.dev/message/msg_ki6v7dz8yiwX
{
  "id": "msg_ki6v7dz8yiwX",
  "inboxId": "ibx_c4dkn8o6frxe",
  "keyEpoch": 0,
  "receivedAt": "2026-11-27T15:56:05.119Z",
  "from": "hello@northlabstudios.com",
  "fromName": "Northlab Studios",
  "to": [],
  "subject": "confirm",
  "text": "Hello, this is a confirm test.\n",
  "attachments": []
}

Without the token, the same request returned 401.

In n8n, build the pull workflow like this:

  1. Webhook trigger, POST, path mailcycle-pull. A Mailcycle webhook sent straight to this trigger delivers the event, so the id sits at body.payload.messageId. The run used a shorter hand-made body, { "messageId": "msg_ki6v7dz8yiwX" }, which is why the screenshot below reads body.messageId.
  2. HTTP Request node, method GET, URL https://your-worker.workers.dev/message/{{ $json.body.payload.messageId }}.
  3. In that node, set Authentication to Generic Credential Type, Generic Auth Type to Header Auth, and create a credential with the name Authorization and the value Bearer <your PULL_TOKEN>.
  4. Edit Fields after it, reading {{ $json.subject }}, because here the node’s output is the message itself, with no body wrapper.
The n8n HTTP Request node named Get opened message: a GET to the helper's /message URL built from body.messageId, with Header Auth, and the message id and inbox id in its output
The HTTP Request node fetches the opened message by id. In the run the helper was local.
The n8n Executions tab for the pull workflow, with the New message, Get opened message and Pick fields nodes all showing a green check
The pull workflow, three nodes, all green.

The expression in the screenshot is the shorter body.messageId because the run’s trigger was called with the small hand-made body. For a delivery from a Mailcycle webhook, use {{ $json.body.payload.messageId }} as in the steps above.

Skip a repeat with eventId

Webhooks are retried, so one email can start the workflow more than once. In push mode, eventId is the same on every try. A simple guard is to keep the ids you have handled and stop when you see one again:

  1. Keep a Google Sheet or a database table with one column, eventId.
  2. After the trigger, look the id up. If a row exists, end the run with a No Operation branch.
  3. If not, run your steps and write the id at the end.

For workflows where a repeat is harmless, such as appending to a log you deduplicate later, you can skip this.

Run n8n on your own machine while you build

Two rules decide whether a local n8n works with the helper:

  • The helper only forwards to an https:// URL. A local n8n therefore needs HTTPS. The run for this tutorial used a self-signed certificate for localhost, started n8n with N8N_PROTOCOL=https, N8N_SSL_KEY, N8N_SSL_CERT and WEBHOOK_URL=https://localhost:5678/, and let the helper trust the certificate with NODE_EXTRA_CA_CERTS.
  • Mailcycle can only call an HTTPS address it can reach. A helper on your laptop is not reachable, so the run sent the signed message.received event itself, built from the documented format and signed with the documented Mailcycle-Signature scheme. Everything after that event was the real path: the API fetch, the opening, the forward and n8n.

For day-to-day building, the usual route is the deployed helper plus a tunnel or a hosted n8n. The webhook tutorial has a section on testing a webhook locally.

An address on your own domain

Everything above works for an address on a shared Mailcycle domain. For an address on your own domain, such as orders@yourcompany.com, use the Scale plan, export that address’s key the same way and add it to ADDRESS_KEYS. The workflow does not change. The role addresses tutorial shows how to set up the domain and the addresses.

One helper can serve several addresses: keep one key per address in ADDRESS_KEYS, and each message is opened with the key for the address it was sent to. When an address gets new keys, it moves to a new key epoch, so export the key again and add it next to the old one:

{ "ibx_k3v9x2mq7a": { "0": "key-for-epoch-0", "1": "key-for-epoch-1" } }

Troubleshooting

The subject, text or from is empty in n8n. You are reading a push delivery without the body prefix. Use {{ $json.body.subject }}. In pull mode the HTTP Request node’s output is the message, so there is no prefix.

Nothing reaches the workflow. Check the workflow is published, since only the production URL works on its own. In the app, open the webhook’s delivery log under API, then Webhooks, and look at the status and error of the latest delivery.

The helper answers 401. The WEBHOOK_SECRET does not match the webhook’s signing secret, or the request is older than five minutes. Copy the whsec_ value again and set the secret. If the error reads Mailcycle API 401, the helper’s MAILCYCLE_API_KEY was revoked or mistyped: create a key and set it again.

The helper answers 500 and does nothing. A secret the request needs is missing: WEBHOOK_SECRET for webhooks, PULL_TOKEN for pull mode, FORWARD_URL for forwarding. Set it with wrangler secret put.

FORWARD_URL must use https. The forward URL has to start with https://. For a local n8n, serve it over HTTPS as described above.

The helper answers 422. A listed address has no key for the message’s epoch, or the key is not the one for this address. Export the address key again and update ADDRESS_KEYS.

A message arrives twice. Retries do that. Use eventId as in the section above.

Mail for an address is skipped. An address that is not in ADDRESS_KEYS is skipped without an error. Add its key.

Security and best practices

The helper holds two things. The address key opens that one address’s mail and nothing else, and it cannot sign in or create keys. The API key can do what any API key does, including sending mail from your addresses, but it cannot create keys. Use a key named for the job and revoke it when the workflow ends.

The helper checks every request. A webhook needs a valid, recent Mailcycle-Signature, a message opens only when its authentication tag verifies for that address and message, and an unexpected error returns internal_error without echoing a secret.

The workflow sees the mail. n8n receives the opened message, so use an address for mail you intend to automate. A separate address per workflow keeps each one to its own mail.

Mail is data. Text in an email is written by the sender. Pass it to a model, a shell step or a template only after you decide how it is treated. If an AI Agent node reads this mail, the n8n AI agent tutorial covers the inbox side of that.

Stop cleanly. To end the workflow, delete the webhook in the app, revoke the helper’s API key on the API keys tab, unpublish the workflow in n8n and delete the Worker if you no longer need it. To stop the old key opening new mail, choose Manage, then Give this address new keys. Export the key again to reconnect the helper.

Which n8n pattern to use

Pattern Use it when
This tutorial: Webhook trigger and the decrypt helper Each email should start a workflow, with no agent and no model. The plan is Operator, or Scale for your own domain.
AI Agent node over MCP An agent should wait for mail, read it and reply in the thread. The plan is Scale.
Your own webhook endpoint You run the receiving code yourself, in any language, and want the SDK to open the message.
Node-RED http in node and the helper You use Node-RED instead of n8n, on a server or a Raspberry Pi.

What you’ve built

Each new email to your address now starts an n8n execution with the plain message: who sent it, the subject, the text, the HTML and the attachments. You also have a pull version that asks for the message by id, and a guard against repeats.

From here, connect the workflow to the job you wanted it for. Add inbound email to your SaaS turns the same events into tickets, Receive email in Node.js and Receive email in Python read mail in code, Mailparser and Parseur alternative pulls order and invoice fields out of each email with a Code node, and Send email from any language covers the sending side. Pricing is on the pricing page.

Read more in the decrypt helper guide, the webhooks guide and the developer overview.

FAQ

How do I trigger an n8n workflow when a new email arrives?

Give the workflow a Webhook trigger, deploy the Mailcycle decrypt helper and set its FORWARD_URL to the trigger's production URL. Add a Mailcycle webhook for message.received that points at the helper. Each new email then starts one execution with the opened message.

Do I need IMAP or a mailbox credential in n8n?

No. The workflow is started by a webhook, so there is no mailbox to poll and no password to store in n8n. The only credential on the n8n side is the optional Header Auth one used in pull mode.

Which plan do I need?

Operator, because webhooks and API keys start there. Use Scale if the address is on your own domain.

Why does my expression return nothing for the subject?

The n8n Webhook trigger puts the JSON it receives under body, so push mode reads {{ $json.body.subject }}. In pull mode the HTTP Request node returns the message itself, so the next node reads {{ $json.subject }}.

What does the workflow receive?

The plain message as JSON: eventId, id, inboxId, keyEpoch, receivedAt, from, fromName, to, subject, text, html and attachments. The helper has already opened the message, so n8n sees the readable content.

How do I get an attachment into n8n?

Set a PULL_TOKEN on the helper. Each entry in attachments then carries a url, and an HTTP Request node with the Header Auth credential downloads the opened file from it, as a file in the node's binary output.

What happens if the webhook is delivered twice?

Webhooks are retried, so a message can reach the workflow twice. eventId is the same on every try, so keep a list of ids you have handled and stop the run when the id is already there.

Can I use a local n8n while building the workflow?

Yes, with two conditions. The helper only forwards to an https:// URL, so serve n8n over HTTPS locally, and Mailcycle can only call an HTTPS address it can reach, so a local run needs a tunnel in front of the helper.

How do I read the mail of an address on my own domain?

Use the Scale plan for the domain, then export the key of that address in the web app and add it to the helper's ADDRESS_KEYS. The rest of the workflow is unchanged.

Does this work with Make, Zapier or Pipedream?

The helper guide covers n8n, Make, Zapier and Pipedream: each has a catch-hook style trigger whose URL you give the helper as FORWARD_URL. This tutorial shows the n8n screens only.

How do I stop the workflow receiving mail?

Delete the webhook in the app (API, then the Webhooks tab), revoke the helper's API key on the API keys tab and unpublish the workflow in n8n.