resend-email-cli
v1.0.1
Published
Command-line interface for Resend - The Email API for Developers
Maintainers
Readme
Resend CLI
A powerful command-line interface for the Resend email API. Send emails, manage domains, contacts, audiences, broadcasts, and webhooks directly from your terminal.
Features
- Email Management - Send single emails, batch emails, schedule delivery, and track status
- Domain Management - Add, verify, and configure sending domains
- Audience Management - Create and manage contact lists
- Contact Management - Add, update, import contacts from CSV
- Broadcast Campaigns - Send bulk emails to audiences
- Webhook Integration - Set up event notifications for email delivery events
- Multiple Output Formats - JSON or human-readable table output
- Scriptable - Perfect for CI/CD pipelines and automation
Installation
# Using npm
npm install -g resend-email-cli
# Using bun
bun install -g resend-email-cliQuick Start
1. Configure your API key
# Interactive setup
resend config init
# Or set directly
resend config set api_key re_xxxxxxxxxxxxx
# Or use environment variable
export RESEND_API_KEY=re_xxxxxxxxxxxxx2. Send your first email
resend emails send \
--from "[email protected]" \
--to "[email protected]" \
--subject "Hello from Resend CLI" \
--text "This email was sent from the command line!"Commands
Configuration
resend config init # Interactive configuration setup
resend config get # Show current configuration
resend config set <key> <value> # Set a configuration value
resend config delete <key> # Remove a configuration valueEmails
# Send a single email
resend emails send --from "[email protected]" --to "[email protected]" --subject "Hello" --text "Body"
# Send with HTML content
resend emails send --from "[email protected]" --to "[email protected]" --subject "Hello" --html "<h1>Hello</h1>"
# Send with HTML file
resend emails send --from "[email protected]" --to "[email protected]" --subject "Hello" --html-file ./email.html
# Send with attachments
resend emails send --from "[email protected]" --to "[email protected]" --subject "Report" --text "See attached" --attachment ./report.pdf
# Schedule email for later
resend emails send --from "[email protected]" --to "[email protected]" --subject "Reminder" --text "Don't forget!" --scheduled-at "2024-12-25T09:00:00Z"
# Send batch emails from JSON file
resend emails send-batch ./emails.json
# Get email details
resend emails get <email-id>
# List sent emails
resend emails list --limit 20
# Update scheduled email
resend emails update <email-id> --scheduled-at "2024-12-26T09:00:00Z"
# Cancel scheduled email
resend emails cancel <email-id>Domains
# List all domains
resend domains list
# Add a new domain
resend domains add example.com --region us-east-1
# Get domain details and DNS records
resend domains get <domain-id>
# Verify domain DNS records
resend domains verify <domain-id>
# Update domain settings
resend domains update <domain-id> --open-tracking --click-tracking
# Delete a domain
resend domains delete <domain-id>Audiences
# List all audiences
resend audiences list
# Create a new audience
resend audiences create "Newsletter Subscribers"
# Get audience details
resend audiences get <audience-id>
# Delete an audience
resend audiences delete <audience-id>Contacts
# List contacts in an audience
resend contacts list <audience-id>
# Add a contact
resend contacts create <audience-id> --email "[email protected]" --first-name "John" --last-name "Doe"
# Get contact details
resend contacts get <audience-id> <contact-id>
# Update a contact
resend contacts update <audience-id> <contact-id> --first-name "Jane"
# Unsubscribe a contact
resend contacts update <audience-id> <contact-id> --unsubscribe
# Delete a contact
resend contacts delete <audience-id> <contact-id>
# Import contacts from CSV
resend contacts import <audience-id> ./contacts.csvBroadcasts
# List all broadcasts
resend broadcasts list
# Create a broadcast
resend broadcasts create <audience-id> --from "[email protected]" --subject "Newsletter" --html-file ./newsletter.html
# Get broadcast details
resend broadcasts get <broadcast-id>
# Update a broadcast
resend broadcasts update <broadcast-id> --subject "Updated Subject"
# Send a broadcast
resend broadcasts send <broadcast-id>
# Delete a broadcast
resend broadcasts delete <broadcast-id>Webhooks
# List all webhooks
resend webhooks list
# Create a webhook
resend webhooks create https://example.com/webhook --events email.sent --events email.delivered
# Get webhook details
resend webhooks get <webhook-id>
# Update webhook events
resend webhooks update <webhook-id> --events email.bounced --events email.complained
# Delete a webhook
resend webhooks delete <webhook-id>Global Options
All commands support these global options:
| Option | Description |
|--------|-------------|
| --api-key <key> | Use a specific API key (overrides config) |
| --output <format> | Output format: json or table (default: json) |
| --verbose | Enable verbose logging |
| --no-color | Disable colored output |
| -h, --help | Display help for command |
Configuration
The CLI stores configuration in ~/.resend/config.json. Configuration priority:
- Command-line flags (
--api-key) - Environment variables (
RESEND_API_KEY) - Configuration file
Environment Variables
| Variable | Description |
|----------|-------------|
| RESEND_API_KEY | Your Resend API key |
File Formats
Batch Email JSON
[
{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Hello 1",
"text": "Message 1"
},
{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Hello 2",
"html": "<h1>Message 2</h1>"
}
]Contact Import CSV
email,first_name,last_name
[email protected],John,Doe
[email protected],Jane,SmithExamples
Send email with CC and BCC
resend emails send \
--from "[email protected]" \
--to "[email protected]" \
--cc "[email protected]" \
--bcc "[email protected]" \
--subject "Important Update" \
--text "Please review the attached document."Send email with tags for tracking
resend emails send \
--from "[email protected]" \
--to "[email protected]" \
--subject "Welcome!" \
--text "Welcome to our service" \
--tag "campaign:welcome" \
--tag "source:signup"Pipe HTML content
cat email.html | resend emails send \
--from "[email protected]" \
--to "[email protected]" \
--subject "Newsletter"Use in CI/CD pipeline
# Send deployment notification
resend emails send \
--api-key $RESEND_API_KEY \
--from "[email protected]" \
--to "[email protected]" \
--subject "Deployment Complete" \
--text "Version $VERSION deployed to production" \
--output jsonJSON output for scripting
# Get email ID from send response
EMAIL_ID=$(resend emails send \
--from "[email protected]" \
--to "[email protected]" \
--subject "Test" \
--text "Test" \
--output json | jq -r '.id')
# Check email status
resend emails get $EMAIL_ID --output json | jq '.status'Webhook Events
Available webhook event types:
email.sent- Email accepted by Resendemail.delivered- Email delivered to recipientemail.delivery_delayed- Delivery temporarily delayedemail.bounced- Email bouncedemail.complained- Recipient marked as spamemail.opened- Email opened (if tracking enabled)email.clicked- Link clicked (if tracking enabled)
API Documentation
For detailed API documentation, visit Resend API Docs.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
