swaks (Swiss Army Knife for SMTP) is an indispensable command-line tool for testing and debugging email server configurations. It can send test emails through any SMTP server with full control over every aspect of the SMTP transaction — authentication, TLS, headers, body content, and attachments. This guide covers practical testing scenarios for mail server administration.
Installation
sudo apt install swaks # Ubuntu/Debian
sudo dnf install swaks # Rocky Linux/RHEL
brew install swaks # macOS
Basic Usage
# Simple test email
swaks --to recipient@example.com --from sender@yourdomain.com --server mail.yourdomain.com
# With SMTP authentication
swaks --to recipient@example.com --from user@yourdomain.com --server mail.yourdomain.com --port 587 --auth LOGIN --auth-user user@yourdomain.com --auth-password 'YourPassword' --tls
# Specify subject and body
swaks --to test@example.com --from user@yourdomain.com --server localhost --header "Subject: Test from swaks" --body "This is a test message sent at $(date)"
Testing TLS/SSL
# Test STARTTLS on port 587
swaks --to test@example.com --server mail.example.com --port 587 --tls --tls-verify
# Test implicit TLS on port 465
swaks --to test@example.com --server mail.example.com --port 465 --tlsc
# Show TLS certificate details
swaks --to test@example.com --server mail.example.com --tls --tls-verify --tls-get-peer-cert
# Test with specific TLS version
swaks --to test@example.com --server mail.example.com --tls --tls-protocol tlsv1_3
Testing Authentication
# Test PLAIN authentication
swaks --to test@example.com --server mail.example.com --port 587 --tls --auth PLAIN --auth-user user@example.com --auth-password password
# Test LOGIN authentication
swaks --to test@example.com --server mail.example.com --port 587 --tls --auth LOGIN --auth-user user@example.com
# Test CRAM-MD5 authentication
swaks --to test@example.com --server mail.example.com --auth CRAM-MD5 --auth-user user
# Show available auth mechanisms
swaks --to test@example.com --server mail.example.com --port 587 --tls --auth-optional-strict --quit-after EHLO
Testing DKIM, SPF, and DMARC
# Send to verification services
swaks --to check-auth@verifier.port25.com --from user@yourdomain.com --server mail.yourdomain.com --port 587 --auth LOGIN --auth-user user@yourdomain.com --tls --header "Subject: Email Auth Test"
# Send to Gmail (check Authentication-Results header in received email)
swaks --to yourgmail@gmail.com --from user@yourdomain.com --server mail.yourdomain.com
# Send to mail-tester.com (get a test address from their site)
swaks --to test-xxxxx@srv1.mail-tester.com --from user@yourdomain.com --server mail.yourdomain.com
Sending Attachments
# Attach a file
swaks --to recipient@example.com --from user@yourdomain.com --server mail.yourdomain.com --attach /path/to/document.pdf --header "Subject: Document attached"
# Multiple attachments
swaks --to recipient@example.com --server mail.yourdomain.com --attach /path/to/file1.pdf --attach /path/to/file2.csv
# Inline HTML body with attachment
swaks --to recipient@example.com --server mail.yourdomain.com --header "Subject: HTML Report" --header "Content-Type: text/html" --body "Monthly Report
See attached.
" --attach /tmp/report.pdf
Testing Spam Filters
# Send GTUBE test string (triggers spam detection)
swaks --to test@yourdomain.com --server localhost --body "XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X"
# Send EICAR test (antivirus detection)
swaks --to test@yourdomain.com --server localhost --attach -