SendEmail CLI Tool
A Rust CLI application for sending templated HTML emails via SMTP with support for batch processing, mail merge, and attachments.
Features
- Send: Send emails to individual or multiple recipients (TO/CC/BCC)
- Batch: Send the same email to a list of recipients from CSV with rate limiting
- Merge: Personalized mail merge using CSV data with per-recipient template variables
- Multi-Profile Support: Manage multiple email accounts via config file
- Template Engine: Handlebars for HTML template rendering
- Attachments: Support for multiple file types with automatic MIME detection
- Rate Limiting: Configurable batch size and delays to avoid SMTP limits
- Progress Tracking: Resume batch operations across sessions
Installation
- Make sure you have Rust installed on your system
- Clone the repository
- Build the project:
Configuration
Email account profiles are configured in config.toml at the project root:
[]
= "smtp.gmail.com"
= 587
= "your.email@gmail.com"
= "Your Name"
= "your-app-password"
[]
= "smtp.office365.com"
= 587
= "work@company.com"
= "Work Account"
Note: If password is omitted, you'll be prompted at runtime.
List Available Profiles
Commands
1. Send Command
Send emails to individual or multiple recipients.
Basic Usage:
Options:
--profile <name>- Email account profile to use--recipients <emails>...- TO recipients--cc-recipients <emails>...- CC recipients--bcc-recipients <emails>...- BCC recipients--subject <text>- Email subject--body <text>- Plain text message (alternative to --template)--template <path>- Path to HTML template file--attachments <files>...- File attachments--data <json>- JSON data for template variables
Examples:
# Simple plain text email
# Email with HTML template and data
# Email with attachments
# Multiple recipients with CC and BCC
2. Batch Command
Send the same email to a list of recipients from a CSV file with rate limiting.
Basic Usage:
Options:
--profile <name>- Email account profile to use--recipients <csv_file>- Path to CSV file with recipient list--subject <text>- Email subject--body <text>- Plain text message (alternative to --template)--template <path>- Path to HTML template file--attachments <files>...- File attachments (same for all recipients)--batch-size <num>- Recipients per batch (default: 25)--delay-minutes <num>- Minutes to wait between batches (default: 5)--limit <num>- Daily email limit (default: 1000)
CSV Format:
email
user1@example.com
user2@example.com
user3@example.com
Or with recipient types:
email,type
user1@example.com,to
manager@example.com,cc
admin@example.com,bcc
Examples:
# Basic batch send
# Batch with attachments and custom settings
# Test batch with limit
Progress Tracking:
- Creates a
.progressfile to track progress - Resumes from last position if interrupted
- Resets daily count at midnight
- Progress file location:
<csv_file>.progress
3. Merge Command
Send personalized emails using CSV data with per-recipient template variables.
Basic Usage:
Options:
--profile <name>- Email account profile to use--data <csv_file>- Path to CSV file with recipient data--subject <text>- Email subject--template <path>- Path to HTML template file (required)--delay-seconds <num>- Seconds to wait between emails (default: 1)--limit <num>- Maximum emails to send (default: 1000)
CSV Format:
The CSV must have an email column. All other columns become template variables.
email,name,event,date
user1@example.com,John Doe,AI Workshop,June 10 2025
user2@example.com,Jane Smith,AI Workshop,June 10 2025
Special Columns:
email- Recipient email address (required)type- Recipient type:to,cc, orbcc(optional, default:to)attachmentorattachments- File paths, semicolon-separated for multiple files (optional)
CSV with Attachments:
email,name,event,attachments
user1@example.com,John Doe,Workshop 1,cert1.pdf
user2@example.com,Jane Smith,Workshop 2,cert2.pdf;badge2.jpg
user3@example.com,Bob Johnson,Workshop 3,cert3.pdf;badge3.jpg;photo3.png
Template Variables:
All CSV columns (except email, type, attachment, attachments) are available in templates:
Hello {{name}}!
Thank you for attending {{event}} on {{date}}.
Your score: {{score}}
Examples:
# Basic mail merge
# Mail merge with per-recipient attachments
# Mail merge with custom delay and limit
Template Engine
Templates use Handlebars syntax for variable substitution.
Example Template:
Welcome
Hello {{name}}!
Thank you for registering.
{{#if link}}
Activate your account
{{/if}}
Variable Sources:
- Send command: Use
--data '{"name":"value"}'JSON - Merge command: CSV columns become template variables automatically
Security Notes
- Password Security: Never commit
config.tomlwith passwords to version control - Use App Passwords: For Gmail/Office365, use app-specific passwords
- Rate Limiting: Respect SMTP provider limits to avoid account suspension
- File Paths: Ensure attachment files exist and are accessible
Troubleshooting
Authentication Failed
- Verify email and password in
config.toml - For Gmail: Enable 2FA and use an App Password
- For Office365: May need to enable SMTP AUTH
Connection Issues
- Check internet connection
- Verify SMTP server and port settings
- Port 587 uses STARTTLS (most common)
Template Errors
- Ensure template file exists at specified path
- Check Handlebars syntax for variables:
{{variable}} - Verify JSON data matches template variables
Attachment Issues
- Verify file paths are correct (absolute or relative to working directory)
- Check file read permissions
- For merge command with multiple attachments, use semicolon separator:
file1.pdf;file2.jpg
Progress File Issues
- Batch progress is stored in
<csv_file>.progress - Delete
.progressfile to start fresh - Progress resets daily email count at midnight
Examples
See examples.sh for comprehensive command examples and CSV-FORMAT.md for detailed CSV format reference.
License
This project is provided as-is for educational and internal use.