How to Use SWAKS with SparkPost
This command line tool allows you to send emails via SMTP. It's easy to use yet offers a wide range of options for advanced needs.

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 .swaksrc configuration 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.
Install SWAKS
sudo yum install epel-release -y && sudo yum install swaks -y
Sending your first email with SWAKS
Once installed, here's the basic syntax to send a message. In this example, we are using the server's local address:
swaks -s 127.0.0.1 -f sender@from.com -t recipient@recipient.com
Send a message with a "Subject" line header plus other headers and include "Hello World!" text in the body:
swaks -s 127.0.0.1
-f me@from.com
-t them@recipient.com
--header "Subject: Hello! This is the subject header"
--header "Second_Header: 123"
--header "Third_Header: XYZ"
--body "Hello World!"
Here's how to add an attachment, where SWAKS handles base64 conversion automatically, making it excellent for testing message size limits:
swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /path/to/file.tgz
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 cron 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.
Using SWAKS with SparkPost SMTP
This time we're going to inject into our SparkPost servers.
Send a message to our SparkPost servers (How tocreate the API key, and the SMTP options). Once you get your authentication key, paste it into the command (make sure to keep the key safe and secure!):
swaks
--server smtp.sparkpostmail.com:587
--tls
--auth-user SMTP_Injection
--auth-password "YOUR_AUTH_KEY"
-f me@from.com
-t them@recipient.com
Testing TLS versions and cipher compatibility
Following security best practices, SparkPost has deprecated all older TLS versions except v1.2 and above. To verify system compatibility, SWAKS allows testing specific TLS versions and ciphers.
swaks
-s smtp.sparkpostmail.com:587
--tls
-f me@from.com
-t them@recipient.com
--auth-user SMTP_Injection
--auth-password "YOUR_API_KEY"
-tlsp tlsv1_2
--tls-cipher ECDHE-RSA-AES128-GCM-SHA256
In this example, "tlsv1_2" is used, but you can change this to "tlsv1_1" and test across other domains to observe their compatibility.
Measuring SMTP connection latency
To measure mail server response speed, SWAKS can proceed through the SMTP cycle and disengage at certain points without sending a message. Time it using the "time" command, which displays results at output's end:
$ time swaks -s 127.0.0.1
-f sender@from.com
-t them@recipient.com
--quit-after RCPT
Automating SWAKS with a configuration file
As promised, if you made it this far the reward is this simple: using a configuration file to set default parameters:
$ cd $HOME
$ vim .swaksrc
Copy and paste the following into the .swaksrc file:
--from swakstest@jasdevism.com
-h-From: "Jas Swaks" <swakstest@jasdevism.com>
-s 127.0.0.1
--body "This is a test!"
--to jsingh@sparkpost.com
Once saved, simply type "swaks" and it pre-populates everything and sends the message. Better yet, override settings by adding parameters on the command line, for instance, to use a different recipient:
swaks -t recipient@somewherelse.com
Other news
Read more from this category