How to Use SWAKS with SparkPost
·
Jun 24, 2021

Key Takeaways
SWAKS (Swiss Army Knife for SMTP) is a powerful command-line tool for sending emails and testing SMTP connections in a flexible, script-friendly way.
It simplifies manual SMTP testing compared to telnet by offering clear flags, authentication handling, attachments, TLS testing, timing, and custom headers.
The tool works across multiple platforms and is beginner-friendly despite its extensive capabilities.
Basic usage includes sending a simple message, adding subject lines, including headers, and sending attachments without manual base64 conversion.
SWAKS is ideal for reliability checks and monitoring — it can be scheduled via cron to perform regular “does it still work?” test sends.
It can also measure latency and connection speed by timing SMTP handshakes without sending a full email.
SWAKS supports detailed TLS testing, including validating compatibility with modern standards such as TLS 1.2 (required by SparkPost).
When using SparkPost, SWAKS allows easy injection into SparkPost SMTP servers using an API key for authentication.
TLS version forcing (e.g.,
tlsv1_2) lets senders test their environments and ensure compliance with SparkPost’s deprecations.SWAKS provides detailed debugging, making it helpful for validating SMTP configurations and diagnosing failed connections.
A
.swaksrcconfiguration file allows users to store default parameters, enabling one-command sending for repeated tests.SWAKS supports command-line overrides, letting users adjust any field dynamically when needed.
Q&A Highlights
What is SWAKS?
A flexible command-line SMTP testing tool known as the “Swiss Army Knife” for email.
Why use SWAKS instead of telnet?
It automates the SMTP handshake, supports authentication, TLS, attachments, and headers, making testing easier and more powerful.
What platforms does SWAKS support?
Linux, macOS, and most Unix-like systems, with similar syntax across them.
How do I send a basic test email with SWAKS?
By running a simple command specifying the recipient, sender, and server address.
Can SWAKS send messages with subject lines and custom headers?
Yes — it supports subjects, from/to overrides, and arbitrary header injection.
Does SWAKS support sending attachments?
Yes — and it automatically handles the base64 encoding for you.
Can SWAKS help test TLS compatibility?
Absolutely — you can force specific TLS versions (like TLS 1.2) or test cipher support.
Why is TLS 1.2 important when sending to SparkPost?
Older TLS versions are deprecated; SparkPost requires TLS 1.2+ for secure connections.
How do I authenticate with SparkPost when using SWAKS?
By using your SparkPost API key as the SMTP password during the command.
Can SWAKS measure performance or latency?
Yes — using the
timecommand and partial SMTP cycles to measure handshake speed.Does SWAKS support automation?
Yes — you can run it via cron jobs to repeatedly test SMTP environments.
What is a .swaksrc file and why use it?
It’s a config file storing default SWAKS parameters, enabling one-command sending with optional overrides.
Last year, we published a blog article that shows how to use the ubiquitous and very useful telnet tool to check an SMTP connection.
The next step is to simplify the manual process by using an awesome “next level” tool (it refers to itself as the Swiss Army Knife of email) called SWAKS. This is a command line tool that can send emails via SMTP. It’s not only easy to use but also simultaneously provides a myriad of options when needed.
At first, I was intimidated by the amount of options, but it is perfectly usable with the most basic options. If you have any issues, just bookmark this page, copy and paste the examples, and modify it to your liking. At the end of this blog, once you have gained some familiarity and don’t have a lot of variance/dynamics to your SWAKS commands, I will show you how to create a configuration file that pre-sets all your defaults parameters. This makes running SWAKS literally a button (OK, “key”) away!
For the purpose of this exercise, we’re going to run the commands from a CentOS 7 server but the commands are similar on all supported platforms. As mentioned above, if you are stuck, just copy and paste directly into your system and modify what you need. Here are the basics:
Install SWAKS
Sending your first email with SWAKS
Advanced SWAKS testing techniques
You’re pretty much set on the basics! Now let’s see how else you can up your setup game. Here are some ideas:
Use a scheduler like chron to do basic ‘does it work’ tests which can work as a foundation or even augment your monitoring system.
Measure latency when connecting and closing a connection to a mail server.
Test different TLS versions and ciphers
You are not going to be left alone here, I will show you how to do all the above.



