Source: https://cli.nylas.com/guides/email-to-slack-notifications

# Email to Slack Alerts from Terminal

Forward important emails to Slack channels automatically from the command line. Poll for new messages, filter by sender or subject, and post formatted alerts using Slack incoming webhooks. Works across Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP providers.

Written by [Prem Keshari](https://cli.nylas.com/authors/prem-keshari) Senior SRE

Updated May 25, 2026

> **TL;DR:** Poll for new emails with `nylas email list --unread --json`, filter with `jq`, and POST to a Slack incoming webhook. Add it to cron and every important email lands in your Slack channel within 60 seconds.

## Why forward email to Slack?

Email-to-Slack is one of the most popular email automation workflows. Gmail-to-Slack is consistently listed among [Zapier's top integration templates](https://zapier.com/apps/gmail/integrations/slack), with millions of active connections. The reason is simple: teams live in Slack during the workday, and critical emails from customers, monitoring systems, or vendors get buried in inboxes. Forwarding those alerts to a Slack channel puts them where people already look.

Zapier and similar tools charge $20-50/month for this workflow and add 1-5 minutes of latency per trigger. A cron job with the Nylas CLI checks for new email every 60 seconds, costs nothing beyond your Nylas plan, and runs entirely on your own infrastructure. The script is 15 lines of bash.

## How do you set up a Slack incoming webhook?

A Slack incoming webhook is a URL that accepts a JSON payload and posts it as a message to a specific channel. Creating one takes under 2 minutes through the Slack API dashboard. According to [Slack's webhook documentation](https://api.slack.com/messaging/webhooks), incoming webhooks support formatted text, attachments, and channel overrides. Each webhook URL is tied to a single workspace and channel.

Go to **api.slack.com/apps**, create a new app (or use an existing one), enable **Incoming Webhooks**, and click **Add New Webhook to Workspace**. Select the channel where email alerts should appear. Slack gives you a URL like `https://hooks.slack.com/services/T00000/B00000/xxxx`. Save this URL — the script below uses it as the delivery target.

## How do you install and authenticate?

The Nylas CLI installs as a single binary with Homebrew. Authentication stores your API key locally in `~/.config/nylas/credentials.json` and covers email, calendar, contacts, and webhooks with a single credential. Setup takes under 60 seconds.

```bash
brew install nylas/nylas-cli/nylas
nylas auth config --api-key <your-nylas-api-key>
```

For shell-script, PowerShell, and Go installs, see the [getting started guide](https://cli.nylas.com/guides/getting-started).

## How do you poll for new emails and forward to Slack?

The script below checks for unread emails every 60 seconds, filters for messages from specific senders, formats them into a Slack message, and posts to your webhook URL. Each iteration queries only unread messages (`--unread` flag), so it skips anything you've already seen. The `jq` pipeline extracts the sender, subject, and a 200-character snippet of the body — enough context to decide whether to act without opening the email.

```bash
#!/bin/bash
# email-to-slack.sh — forward important emails to Slack
SLACK_WEBHOOK="https://hooks.slack.com/services/T00000/B00000/xxxx"

# Fetch unread emails as JSON
EMAILS=$(nylas email list --unread --json)
[ -z "$EMAILS" ] && exit 0
COUNT=$(echo "$EMAILS" | jq 'length // 0')

if [ "$COUNT" -gt 0 ]; then
  echo "$EMAILS" | jq -c '.[]' | while read -r email; do
    SENDER=$(echo "$email" | jq -r '.from[0].email // "unknown"')
    SUBJECT=$(echo "$email" | jq -r '.subject // "(no subject)"')
    SNIPPET=$(echo "$email" | jq -r '.snippet // "" | .[0:200]')

    # Post to Slack
    curl -s -X POST "$SLACK_WEBHOOK" \
      -H "Content-Type: application/json" \
      -d "$(jq -n \
        --arg sender "$SENDER" \
        --arg subject "$SUBJECT" \
        --arg snippet "$SNIPPET" \
        '{text: "*New email from \($sender)*\n>*Subject:* \($subject)\n>\($snippet)"}'
      )"
  done
  echo "Forwarded $COUNT emails to Slack"
fi
```

## How do you filter for specific senders or subjects?

Not every email deserves a Slack alert. The `--from` flag on `nylas email list` filters by sender address at the API level, so only matching messages are returned. For subject-line filtering, use `nylas email search` with a query string. Combining both reduces API calls and keeps Slack noise-free. A typical setup monitors 3-5 critical senders — monitoring tools, payment processors, and key customers.

```bash
# Only emails from monitoring systems
nylas email list --unread --from "alerts@datadog.com" --json

# Only emails with "CRITICAL" in the subject
nylas email search "CRITICAL" --unread --json

# Combine: emails from PagerDuty with "incident" in subject
nylas email search "incident" --from "no-reply@pagerduty.com" --json
```

## How do you schedule it with cron?

Add the script to your crontab to check for new emails every minute. The CLI reads credentials from `~/.config/nylas/credentials.json` automatically, so no interactive login interrupts the cron job. A 60-second polling interval catches most emails within 90 seconds of arrival — faster than Zapier's free-tier 15-minute polling and comparable to their paid 1-minute tier at $0/month.

```bash
# Check every minute
* * * * * /bin/bash $HOME/email-to-slack.sh >> $HOME/email-to-slack.log 2>&1

# Check every 5 minutes (lower API usage)
*/5 * * * * /bin/bash $HOME/email-to-slack.sh >> $HOME/email-to-slack.log 2>&1
```

## How do you use Nylas webhooks for real-time delivery?

Polling works for most setups, but if you need sub-second delivery, Nylas webhooks push a `message.created` event to your server the moment a new email arrives. The `nylas webhook create` command registers a webhook endpoint in one command. Your server receives a JSON payload with the message ID, then fetches the full message and posts to Slack. This approach handles 10,000+ messages per day without polling overhead.

```bash
# Register a webhook for new messages
nylas webhook create \
  --url "https://your-server.com/email-hook" \
  --triggers message.created \
  --description "Email to Slack forwarder"

# Test webhook locally (starts a tunnel + local server)
nylas webhook server --port 8080
```

## Next steps

Get the CLI running with the [getting started guide](https://cli.nylas.com/guides/getting-started). For more webhook patterns, see [parse inbound email webhooks](https://cli.nylas.com/guides/parse-inbound-email-webhooks) and [test webhooks locally](https://cli.nylas.com/guides/test-email-webhooks-locally). To build richer notifications with AI-generated summaries, combine this workflow with [email thread summarization](https://cli.nylas.com/guides/summarize-email-threads-ai). The full [command reference](https://cli.nylas.com/docs/commands) covers all webhook and email list flags.
