Source: https://cli.nylas.com/guides/n8n-email-automation

# n8n Email Automation Across Providers

n8n is a self-hostable automation tool, and its built-in Gmail and Outlook nodes each want their own OAuth app registration before they'll send a single message. If your workflow has to touch more than one provider, that's a lot of setup. Calling the Nylas CLI from an Execute Command node sidesteps it: one authenticated tool reads and sends across six providers and returns JSON your workflow can parse. Here's the pattern.

Written by [Pouya Sanooei](https://cli.nylas.com/authors/pouya-sanooei) Software Engineer

Updated June 8, 2026

> **TL;DR:** n8n's native Gmail and Outlook nodes each need a separate OAuth app. An Execute Command node that runs `nylas email list --json` or `nylas email send` gives an n8n workflow email across six providers from one authenticated tool, with JSON output that flows straight into the next node. Pair it with a Webhook node and `nylas webhook create` to trigger on new mail.

Command references used in this guide: [`nylas email list`](https://cli.nylas.com/docs/commands/email-list), [`nylas email send`](https://cli.nylas.com/docs/commands/email-send), and [`nylas webhook create`](https://cli.nylas.com/docs/commands/webhook-create).

## How do you add email to an n8n workflow?

You add email to n8n by running the Nylas CLI from an Execute Command node. That node runs a shell command on the n8n host and captures its output, so `nylas email list --json` returns the inbox as structured data the next node can read. The [Execute Command node docs](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executecommand/) describe how stdout becomes workflow data.

The CLI must be installed on the n8n host and authenticated once with `nylas auth login`; after that, the stored grant is reused by every workflow run. Because output is JSON, you pipe it into n8n's Code or Set nodes without parsing HTML or scraping a UI. This works the same on n8n Cloud's self-hosted runners and a Docker deployment, as long as the binary is present.

## Why use the CLI instead of n8n's built-in nodes?

[n8n](https://n8n.io/) ships Gmail and Microsoft Outlook nodes, and they work well — for one provider at a time. Each requires you to register an OAuth application with that provider, configure credentials, and manage scopes; a workflow spanning Gmail, Outlook, and Yahoo means three separate setups. The CLI consolidates that into one authenticated tool covering six providers, so adding a provider is a login, not a new app registration.

The other gain is uniform output. The native nodes return provider-shaped data; the CLI returns the same JSON schema whether the account is Gmail or iCloud, so a workflow built for one provider runs unchanged against another. For a multi-provider automation, that single shape removes per-provider branching in your Code nodes.

## How do you read email in an n8n workflow?

Put an Execute Command node early in the workflow that runs `nylas email list --unread --json`. The node's stdout is the unread inbox as JSON; a following Code node parses it and emits one item per message, which downstream nodes process individually. This is the read half of most automations — pull mail, then act on each message.

```bash
# Execute Command node — read unread mail as JSON
nylas email list --unread --json --limit 25

# In a following Code node, fan out one item per email:
# const emails = JSON.parse($input.first().json.stdout);
# return emails.map((e) => ({ json: e }));
```

## How do you send email and trigger on new mail?

For sending, an Execute Command node runs `nylas email send` with values mapped from earlier nodes — an approval step, a database lookup, an AI draft. The message goes out from the connected account across whichever provider it belongs to. Because it's one command, the same node handles Gmail and Outlook sends without branching.

For triggering, combine an n8n [Webhook node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/) with `nylas webhook create`: point the webhook subscription at your n8n Webhook node's URL and the `message.created` trigger, and the workflow fires when new mail arrives — no polling. Verify the `x-nylas-signature` on the incoming request in a Code node before acting, since the webhook URL is public.

```bash
# Execute Command node — send, using values from earlier nodes
nylas email send --to "$RECIPIENT" \
  --subject "Approved: $TICKET" \
  --body "Your request was approved."

# Trigger the workflow on new mail (point at your n8n Webhook node URL)
nylas webhook create \
  --url https://your-n8n.example.com/webhook/new-mail \
  --triggers message.created
```

## Can n8n use the Nylas MCP server instead?

Yes. n8n added support for MCP, so an MCP Client Tool node can call the Nylas MCP server (`nylas mcp serve`) and expose email and calendar tools to an AI Agent node. That suits workflows where a model decides which action to take, rather than a fixed sequence of Execute Command steps. The Execute Command approach is simpler for deterministic automations; the MCP approach fits agentic ones.

Either way, the underlying access is the same authenticated Nylas connection across six providers. Choose Execute Command when the workflow logic is fixed and you want plain JSON; choose the MCP node when an AI Agent node should pick actions dynamically. See the [MCP email server setup](https://cli.nylas.com/guides/mcp-email-server-setup) for running the server and [email-to-Slack notifications](https://cli.nylas.com/guides/email-to-slack-notifications) for a worked automation.

## Next steps

- [MCP email server setup](https://cli.nylas.com/guides/mcp-email-server-setup) — run the server for AI Agent nodes
- [Email to Slack notifications](https://cli.nylas.com/guides/email-to-slack-notifications) — a worked automation pattern
- [Verify webhook signatures](https://cli.nylas.com/guides/webhook-signature-verification) — validate the trigger payload
- [Extract email data with jq](https://cli.nylas.com/guides/extract-email-data-jq) — shape JSON between nodes
- [Full command reference](https://cli.nylas.com/docs/commands) — every flag and subcommand documented
