swaks
Swaks is a command-line SMTP test tool for testing SMTP setups, supporting STARTTLS and various authentication methods like PLAIN, LOGIN, CRAM-MD5, SPA, and DIGEST-MD5. It allows stopping the SMTP dialog at any stage, such as checking RCPT TO without sending a full email.
Description
Swaks (Swiss Army Knife SMTP) is a flexible, scriptable tool written in Perl designed for testing SMTP servers, including ESMTP and LMTP protocols. It supports multiple transport methods like network sockets, UNIX domain sockets, and pipes, making it ideal for operators and scripters who need to verify SMTP configurations without repeatedly using telnet.
Common use cases include delivering test emails, testing virus scanners with EICAR attachments, spam scanners with GTUBE, authentication mechanisms, and recipient verification. It can automate checks on multiple recipients from a file and supports advanced features like TLS negotiation and pipelining.
The tool processes options from configuration files, environment variables, and command line, with later settings overriding earlier ones. It distinguishes between envelope (true sender/recipients) and message headers/body, providing precise control over SMTP transactions.
How It Works
Swaks connects to a target via transports (network sockets default, UNIX sockets, or pipes) and communicates using SMTP/ESMTP/LMTP protocols. It handles features like STARTTLS for TLS, SMTP AUTH, pipelining, and XCLIENT. Options define envelope sender/recipients, HELO/EHLO strings, headers, body, and stop points (e.g., after RCPT or STARTTLS). The transaction follows SMTP flow: connect, banner, HELO/EHLO, MAIL FROM, RCPT TO, DATA (headers + body), QUIT. Users can quit early with --quit-after, use custom DATA, or test via pipes to spawned processes. Configuration prioritizes command line over env vars over files, with no- prefix to unset options.
Installation
sudo apt install swaksFlags
Examples
swaks --to test@example.net --server test-server.example.netswaks --to test@example.net --from user@example.com --auth CRAM-MD5 --auth-user user@example.com --header-X-Test "test email"swaks -t test@example.com --attach - --server test-server.example.com --suppress-data </path/to/eicar.txtswaks --to test@example.com --body @/path/to/gtube/fileswaks --to test@example.com --socket /var/lda.sock --protocol LMTPfor E in `cat /path/to/email/file`; do swaks --to $E --server test-server.example.com --quit-after RCPT --hide-all; [ $? -ne 0 ] && echo $E; done