Skip to content

Swaks

Swaks is the "Swiss Army Knife for SMTP". First released in 2003, it has become a go-to tool for testing mail servers and diagnosing SMTP connection issues, and there's very little it can't do. It's particularly useful for verifying server details and credentials, and sending quick tests.

All the available options can be a little overwhelming though, so here are some common useful examples.

Installation

Swaks is available in most package managers, so installing Swaks on macOS or Linux is a breeze:

macOS

  • Homebrew - brew install swaks
  • MacPorts - port install swaks

Linux

  • Debian / Ubuntu - sudo apt-get install swaks
  • Fedora - sudo dnf install swaks
  • Arch - sudo pacman -S swaks

Windows

There's no packaged version for Windows, however installing Windows Subsystem for Linux (WSL) and then following the Linux installation instructions may be the easiest way.

Send a simple test email

This example will send a simple plain text email with a subject such as test Fri, 04 Jul 2025 11:54:51 +0000, and a message body of This is a test mailing

swaks \
  --from [email protected] \
  --to [email protected] \
  --server in.smtp.sendamatic.net:587 \
  --auth plain \
  --tls \
  --auth-user [mail credential user] \
  --auth-password [mail credential password]

Send attachments

Attaching files can be done with the --attach option, which can be added multiple times.

swaks \
  --from [email protected] \
  --to [email protected] \
  --server in.smtp.sendamatic.net:587 \
  --auth plain \
  --tls \
  --auth-user [mail credential user] \
  --auth-password [mail credential password] \
  --h-Subject 'Attachment test' \
  --body 'Attachment test' \
  --attach @/path/file-1.txt \
  --attach @/path/file-2.txt

Resend an existing email

It can sometimes be useful to resend an existing email, such as from an .eml file. The raw data can be passed in via the --data option.

swaks \
  --from [email protected] \
  --to [email protected] \
  --server in.smtp.sendamatic.net:587 \
  --auth plain \
  --tls \
  --auth-user [mail credential user] \
  --auth-password [mail credential password] \
  --data @/path/file.eml

Send to multiple recipients

A comma seperated list of recipients can be passed into the --to option.

swaks \
  --from [email protected] \
  --to [email protected],[email protected] \
  --server in.smtp.sendamatic.net:587 \
  --auth plain \
  --tls \
  --auth-user [mail credential user] \
  --auth-password [mail credential password]

Send a BCC email

A BCC email has envelope senders that doesn't appear in the 'To' header. Swaks gives you full control over both of these.

swaks \
  --from [email protected] \
  --to [email protected],[email protected] \
  --header "To: [email protected]" \
  --server in.smtp.sendamatic.net:587 \
  --auth plain \
  --tls \
  --auth-user [mail credential user] \
  --auth-password [mail credential password]

Adding headers

Headers can be added in a couple of ways. Say you wanted to add a List-ID header:

If the header already exists in DATA (e.g. you're resending an existing file), this first example will replace the header.

# Both these syntaxes behave in the same way
--header-List-ID "<mailing-list-name.domain.com>"
--header "List-ID: <mailing-list-name.domain.com>"

This second example will add a new header at the end of the existing headers, wether the same one already existed or not:

--add-header "List-ID: <mailing-list-name.domain.com>"

TLS

Slightly confusingly, the --tls flag refers to STARTTLS, which is a way of negotiating a secure connection over an unsecured port. If you wish to connect to a TLS secured port (typically port 465), use the --tls-on-connect flag instead.

swaks \
  --from [email protected] \
  --to [email protected] \
  --server in.smtp.sendamatic.net:465 \
  --auth plain \
  --tls-on-connect \
  --auth-user [mail credential user] \
  --auth-password [mail credential password]

Further reading