Introduction
In system administration and development environments, it’s often necessary to test email-sending functionality without relying on a full application or framework. Swaks (Swiss Army Knife for SMTP) is a powerful command-line tool that lets you manually test SMTP with Swaks and validate email delivery. This guide covers how to test SMTP with Swaks using the SMTP2GO service, sending a test email over TLS with login authentication.
Implementation
I. Prerequisites
Before running the Swaks command, make sure the following are in place:
1. Swaks installed
- Debian/Ubuntu:
sudo apt install swaks - macOS (Homebrew):
brew install swaks
2. An SMTP2GO account
- A registered and configured SMTP2GO account
- The SMTP server address, port number, and your SMTP username and password
3. Network access
- The machine running Swaks needs outbound access to external SMTP servers on port 587
4. TLS support
- Your Swaks build should include TLS support to enable secure communication
5. Valid email addresses
- A valid sender address (
--from) and recipient address (--to)
II. How to Test SMTP with Swaks
Here’s the command to test SMTP with Swaks through SMTP2GO using TLS and login authentication:
swaks --to sam@gmail.com \
--from dev@solutions.com \
--server smtp2go.com \
--auth LOGIN \
--auth-user admin@solutions.com \
--auth-password 'yourpassword' \
--port 587 \
--tls \
--body "This is a test message sent using swaks."
What each flag does:
| Flag | Purpose |
|---|---|
--to | Recipient email address |
--from | Sender email address |
--server | SMTP server hostname (SMTP2GO in this case) |
--auth LOGIN | Authentication method to use |
--auth-user | SMTP account username |
--auth-password | SMTP account password |
--port | SMTP port (587 is the standard submission port for TLS) |
--tls | Enables TLS encryption for the connection |
--body | The message body to send |
If everything is configured correctly, Swaks prints the full SMTP conversation to your terminal — including the connection handshake, authentication, and delivery confirmation — making it easy to spot exactly where a failure occurs if something goes wrong.
Security note: The example above includes
--auth-passworddirectly on the command line for clarity, but this isn’t safe for production or shared environments — plaintext passwords in commands can end up in shell history or process listings visible to other users on the same machine. See the next step for safer alternatives.
III. Avoid Hardcoding Credentials
Once you’re ready to test SMTP with Swaks in a production or shared environment, avoid embedding credentials directly in the command.
Use an environment variable:
export SMTP_PASS='yourpassword'
swaks --to sam@gmail.com \
--from dev@solutions.com \
--server smtp2go.com \
--auth LOGIN \
--auth-user admin@solutions.com \
--auth-password "$SMTP_PASS" \
--port 587 \
--tls
Or use a secrets manager: tools like pass, HashiCorp Vault, or your cloud provider’s secret manager can inject credentials at runtime instead of storing them in scripts or shell history.
IV. Conclusion
Swaks provides a simple and efficient way to validate email configurations and troubleshoot SMTP-related issues. Whether you’re testing from a local machine or integrating email into a larger workflow, using Swaks to test SMTP gives you detailed, low-level control over message sending and clear visibility into the SMTP conversation. For secure and production environments, always avoid embedding credentials in plain text — use environment variables or a proper secrets manager instead.
For more sysadmin testing and automation guides, see our post on creating a Jenkins user and managing permissions.
Frequently Asked Questions
Why use port 587 instead of 25? Port 587 is the standard “submission” port designed for authenticated email sending with TLS. Port 25 is typically used for server-to-server mail transfer and is often blocked by ISPs for outbound connections.
What if the connection fails or times out? Check that outbound port 587 isn’t blocked by a firewall, confirm your SMTP2GO credentials are correct, and verify your Swaks build includes TLS support (swaks --help will show available options).
Can Swaks test other SMTP providers besides SMTP2GO? Yes — you can test SMTP with Swaks against any standard SMTP server. Just swap the --server, --auth-user, and --auth-password values for your provider’s details.