Send Emails from the Command Line with Swaks
Send emails through AhaSend’s SMTP servers directly from your terminal using Swaks, a powerful command-line tool designed for testing and debugging SMTP servers. Perfect for scripting, automation, and troubleshooting email delivery issues.What is Swaks? Swaks (Swiss Army Knife for SMTP) is a versatile, scriptable tool for testing SMTP servers and sending emails from the command line. It supports TLS encryption, various authentication methods, and is designed as a diagnostic tool rather than for high-volume sending.
Prerequisites
Before you begin, ensure you have:System Requirements
System Requirements
- Swaks installed on your system
- Command line access (Terminal, Command Prompt, etc.)
- Basic familiarity with command-line tools
AhaSend Setup
AhaSend Setup
- Domain verified in your AhaSend account
- SMTP credentials created (username and password)
- Access to your AhaSend dashboard for credential management
Need SMTP Credentials? If you haven’t created SMTP credentials yet, check out our SMTP Credentials guide for step-by-step instructions.
Installation
Install Swaks using your system’s package manager:Connection Settings
Use these settings for all Swaks commands with AhaSend:Primary Server
Host:
send.ahasend.com
Ports: 587 (recommended), 25, 2525
Security: TLS (—tls flag)
Authentication: Plain (—auth plain)US Server
Host:
send-us.ahasend.com
Ports: 587 (recommended), 25, 2525
Security: TLS (—tls flag)
Authentication: Plain (—auth plain)Basic Email Examples
Advanced Examples
Using Special Headers
Add AhaSend’s special headers to control tracking, retention, and other features:Testing with Sandbox Mode
Use sandbox mode to safely test your email integration:Sandbox Benefits: Emails sent in sandbox mode are free, trigger webhooks normally, and never actually deliver to recipients - perfect for development and testing.
Scripting and Automation
Shell Script Example
Email Script Example
Environment Variables
For security, use environment variables for credentials:Environment Setup
Resources
Swaks Documentation
Official Swaks documentation and manual
SMTP Testing Guide
Complete guide to testing email delivery
AhaSend SMTP Settings
SMTP server configuration and credentials
AhaSend Support
Get help from our engineering team
Pro Tip: Start with sandbox mode and basic commands before building complex automation. Use environment variables for credentials and always test scripts thoroughly before production use.