DEV Community

Qasim Muhammad
Qasim Muhammad

Posted on

Automate Your Entire Email Workflow from the Terminal — No SMTP, No Sendmail

You have a cron job that needs to send a report every morning. A CI pipeline that emails test results. An AI agent that triages your inbox. All of these need email — and all of them hate SMTP configuration.

The Nylas CLI handles email through Gmail, Outlook, Exchange, Yahoo, iCloud, and IMAP from a single command-line interface. No SMTP server. No app passwords. No sendmail configuration. Here's how to build a complete email automation workflow.

Step 1: Get Set Up in 2 Minutes

Install and authenticate:

brew install nylas/nylas-cli/nylas
nylas init
Enter fullscreen mode Exit fullscreen mode

nylas init runs a 4-step wizard: account creation, app selection, API key generation, and email sync. For CI/CD, skip the wizard:

nylas init --api-key nyl_abc123
Enter fullscreen mode Exit fullscreen mode

Already have credentials? Use nylas auth config to store your API key, then nylas auth login to connect a mailbox via OAuth.

Want to try it without connecting a real account? nylas demo email list shows sample data with zero configuration.

Pro tip: run nylas completion bash and pipe the output to your shell's completion directory — every flag and subcommand gets tab-completion.

Step 2: Read Your Inbox

List recent messages:

nylas email list --limit 20
Enter fullscreen mode Exit fullscreen mode

nylas email list supports filters that make automation practical:

# Unread only
nylas email list --unread --json

# From a specific sender
nylas email list --from boss@company.com

# Only messages with attachments
nylas email list --has-attachment --json | jq '.[].subject'
Enter fullscreen mode Exit fullscreen mode

Read a specific message with nylas email read:

nylas email read msg_abc123 --raw
Enter fullscreen mode Exit fullscreen mode

If the message is GPG-encrypted, add --decrypt --verify to decrypt and verify the signature inline.

Step 3: Search Like You Mean It

nylas email search queries across your entire mailbox:

nylas email search "invoice" --after 2025-01-01 --limit 10 --json
Enter fullscreen mode Exit fullscreen mode

Filter by sender, date range, read status, or attachment presence. Pipe --json output into jq to extract exactly the fields you need.

Step 4: Send Email — One Command

nylas email send handles plain sends, scheduled delivery, GPG encryption, and tracking:

# Basic send
nylas email send \
  --to user@example.com \
  --subject "Daily Report" \
  --body "See attached metrics." --yes

# Schedule for 2 hours from now
nylas email send \
  --to team@company.com \
  --subject "Reminder" \
  --body "Standup in 30 minutes" \
  --schedule 2h

# GPG signed and encrypted
nylas email send \
  --to legal@partner.com \
  --subject "Contract v2" \
  --body "Attached." \
  --sign --encrypt
Enter fullscreen mode Exit fullscreen mode

Check what's queued with nylas email scheduled list.

Step 5: Let AI Write Your Emails

nylas email smart-compose generates drafts from natural language:

nylas email smart-compose \
  --prompt "Decline the meeting politely, suggest next week" \
  --to manager@company.com
Enter fullscreen mode Exit fullscreen mode

Pass --thread-id to give the AI context from an existing conversation.

For inbox analysis, nylas email ai analyze extracts sentiment, action items, and summaries:

nylas email ai analyze --id msg_abc123 --prompt "What action items are in this email?"
Enter fullscreen mode Exit fullscreen mode

Step 6: Manage Messages at Scale

Batch operations from shell scripts:

# Mark all unread as read
nylas email list --unread --json | jq -r '.[].id' | while read id; do
  nylas email mark read --id "$id"
done

# Star important messages
nylas email mark starred --id msg_xyz789
Enter fullscreen mode Exit fullscreen mode

Other management commands:

Putting It Together: A Cron Job

Here's a real example — a daily script that emails you a summary of unread messages:

#!/bin/bash
COUNT=$(nylas email list --unread --json | jq length)
SUBJECTS=$(nylas email list --unread --json --limit 5 | jq -r '.[].subject' | head -5)

nylas email send \
  --to me@company.com \
  --subject "Inbox Summary: $COUNT unread" \
  --body "Top 5 subjects:\n$SUBJECTS" \
  --yes
Enter fullscreen mode Exit fullscreen mode

Add it to crontab: 0 8 * * * /path/to/inbox-summary.sh

Full Command Reference

Every command shown here has a detailed reference page with all flags, examples, and troubleshooting at the Nylas CLI Command Reference.

Top comments (1)

Collapse
 
bhavin-allinonetools profile image
Bhavin Sheth

This is super clean 👌
I’ve struggled with SMTP setup in scripts before, and it always breaks at the worst time. Using a single CLI for sending + reading emails (especially with cron/CI) feels way more reliable and dev-friendly.