Skip to main content
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 sending, verify your domain and create an SMTP credential. Use a sandbox credential for these examples so no email is delivered. Keep the username and password in your server’s secret store. Before you begin, ensure you have:
  • Swaks installed on your system
  • Command line access (Terminal, Command Prompt, etc.)
  • Basic familiarity with command-line tools

Installation

Install Swaks using your system’s package manager:

Connection Settings

All message data is stored in the EU. See SMTP limits.

Basic Email Examples

On port 465, use --tls-on-connect instead of --tls. Port 465 accepts --auth login and --auth plain.

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

Send with the AhaSend CLI

The AhaSend CLI can also send a test email over SMTP, with ahasend smtp send. It connects to --server, which defaults to send.ahasend.com:587, and starts TLS: at once on port 465, otherwise with STARTTLS when the server offers it. AhaSend’s own servers do not offer implicit TLS on port 465, so use port 587, 25 or 2525 with them. It refuses to send the username, the password or the message to a server that offers no STARTTLS, except on localhost, 127.0.0.1 or ::1. --password-stdin reads the password from the first line of stdin, so it stays out of the process list and your shell history:
Sandbox Send with the AhaSend CLI
--test connects, starts TLS when the server offers it, logs in when you give the username and the password, and quits without sending a message:
Connection Test with the AhaSend CLI
The CLI flags --sandbox, --sandbox-result, --tag, --track-opens and --track-clicks set the matching AhaSend headers. See ahasend smtp for every flag and exit code.

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.