DEV Community

Qasim Muhammad
Qasim Muhammad

Posted on • Edited on • Originally published at cli.nylas.com

A Practical Guide to nylas email delete

Scripts, cron jobs, and AI agents all need email access. nylas email delete provides it without SMTP configuration.

The nylas email delete command permanently removes a message from the provider. On Gmail this moves to Trash; on IMAP it sets the \Deleted flag.

How It Works

The Nylas CLI abstracts away the differences between Gmail's API, Microsoft Graph, Exchange Web Services, and raw IMAP. You write one command; it works across all providers. This matters for automation — your cron job or CI pipeline doesn't need provider-specific logic.

Syntax

nylas email delete --id MESSAGE_ID [--force]
Enter fullscreen mode Exit fullscreen mode

When to use this command

Use with caution — deletion is permanent for most providers. Consider nylas email mark-read or archiving instead if you just want to clean up.

Best for: automated cleanup of test emails, CI/CD inbox maintenance, or bulk removal of processed messages after export.

Examples

Delete a specific email:

nylas email delete --id msg_abc123
Enter fullscreen mode Exit fullscreen mode

Batch delete old emails with jq pipe:

nylas email list --json --limit 50 | jq -r '.[].id' | xargs -I{} nylas email delete --id {} --force
Enter fullscreen mode Exit fullscreen mode

Key Flags

Run nylas email delete --help to see all available flags. Add --json for machine-readable output — useful when piping into jq or feeding data to scripts.

nylas email delete --help
Enter fullscreen mode Exit fullscreen mode

Related posts

Full docs: nylas email delete reference — all flags, advanced examples, and troubleshooting.

All commands: Nylas CLI Command Reference

Get started: brew install nylas/nylas-cli/nylasother install methods

Top comments (0)