How to Use SWAKS with SparkPost

Bird

Jun 24, 2021

Email

1 min read

How to Use SWAKS with SparkPost

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 time command 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.

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.

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:

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:

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

sudo yum install epel-release -y && sudo yum install swaks -y

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 + other headers and then include a “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 does the base64 conversion for you, great for testing message size limits:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /path/to/file.tgz

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. This time we’re going to inject into our SparkPost servers.

Send a message to our SparkPost servers (How to create 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

If you’re looking for guidance on how to troubleshoot sending via SMTP to our servers, check out our SMTP troubleshooting article. For basic SMTP connection testing, you can also verify SMTP connections using manual telnet sessions.

Echoing best security practices, SparkPost has deprecated all older TLS versions except v1.2 and above. If you want to see if your system is compatible, SWAKS allows you to test 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, we are using “tlsv1_2” but go ahead and change that to “tlsv1_1” and use it on other domains to observe their compatibility.

What if you want to time how fast a mail server responds? SWAKS can go through the SMTP cycle and disengage at some points without sending a message, and you can time it using the “time” command which shows at end of output:

$ time swaks -s 127.0.0.1 
  -f sender@from.com 
  -t them@recipient.com 
  test 
  --quit-after RCPT
=== Trying 127.0.0.1:25...
=== Connected to 127.0.0.1.
...
 -> RCPT TO:<them@recipient.com>
<- 250 2.1.5 <them@recipient.com> ok
 -> QUIT
<

As promised, if you made it this far the reward is this simple sing a configuration file to set default parameters:

$ cd $HOME
$ vim .swaksrc

Copy and paste this 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 you save it, just type “swaks“ and it pre-populates everything and sends it on its merry way! Even better, you can override by adding it on the command line, say for example you want a different recipient:

swaks -t recipient@somewherelse.com
sudo yum install epel-release -y && sudo yum install swaks -y

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 + other headers and then include a “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 does the base64 conversion for you, great for testing message size limits:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /path/to/file.tgz

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. This time we’re going to inject into our SparkPost servers.

Send a message to our SparkPost servers (How to create 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

If you’re looking for guidance on how to troubleshoot sending via SMTP to our servers, check out our SMTP troubleshooting article. For basic SMTP connection testing, you can also verify SMTP connections using manual telnet sessions.

Echoing best security practices, SparkPost has deprecated all older TLS versions except v1.2 and above. If you want to see if your system is compatible, SWAKS allows you to test 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, we are using “tlsv1_2” but go ahead and change that to “tlsv1_1” and use it on other domains to observe their compatibility.

What if you want to time how fast a mail server responds? SWAKS can go through the SMTP cycle and disengage at some points without sending a message, and you can time it using the “time” command which shows at end of output:

$ time swaks -s 127.0.0.1 
  -f sender@from.com 
  -t them@recipient.com 
  test 
  --quit-after RCPT
=== Trying 127.0.0.1:25...
=== Connected to 127.0.0.1.
...
 -> RCPT TO:<them@recipient.com>
<- 250 2.1.5 <them@recipient.com> ok
 -> QUIT
<

As promised, if you made it this far the reward is this simple sing a configuration file to set default parameters:

$ cd $HOME
$ vim .swaksrc

Copy and paste this 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 you save it, just type “swaks“ and it pre-populates everything and sends it on its merry way! Even better, you can override by adding it on the command line, say for example you want a different recipient:

swaks -t recipient@somewherelse.com
sudo yum install epel-release -y && sudo yum install swaks -y

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 + other headers and then include a “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 does the base64 conversion for you, great for testing message size limits:

swaks -s 127.0.0.1 -f me@from.com -t them@recipient.com --attach /path/to/file.tgz

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. This time we’re going to inject into our SparkPost servers.

Send a message to our SparkPost servers (How to create 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

If you’re looking for guidance on how to troubleshoot sending via SMTP to our servers, check out our SMTP troubleshooting article. For basic SMTP connection testing, you can also verify SMTP connections using manual telnet sessions.

Echoing best security practices, SparkPost has deprecated all older TLS versions except v1.2 and above. If you want to see if your system is compatible, SWAKS allows you to test 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, we are using “tlsv1_2” but go ahead and change that to “tlsv1_1” and use it on other domains to observe their compatibility.

What if you want to time how fast a mail server responds? SWAKS can go through the SMTP cycle and disengage at some points without sending a message, and you can time it using the “time” command which shows at end of output:

$ time swaks -s 127.0.0.1 
  -f sender@from.com 
  -t them@recipient.com 
  test 
  --quit-after RCPT
=== Trying 127.0.0.1:25...
=== Connected to 127.0.0.1.
...
 -> RCPT TO:<them@recipient.com>
<- 250 2.1.5 <them@recipient.com> ok
 -> QUIT
<

As promised, if you made it this far the reward is this simple sing a configuration file to set default parameters:

$ cd $HOME
$ vim .swaksrc

Copy and paste this 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 you save it, just type “swaks“ and it pre-populates everything and sends it on its merry way! Even better, you can override by adding it on the command line, say for example you want a different recipient:

swaks -t recipient@somewherelse.com

Other news

Read more from this category

A person is standing at a desk while typing on a laptop.

The complete AI-native platform that scales with your business.

© 2025 Bird

A person is standing at a desk while typing on a laptop.

The complete AI-native platform that scales with your business.

© 2025 Bird