Swaks
Swaks is the "Swiss Army Knife for SMTP". First released in 2003, it has become one of the most popular command line tools 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, and we regularly use it here.
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, 06 Jul 2025 08:44: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]
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]
Output
Swaks will display the SMTP conversation in its output, with some additional hints. Full details can be found in the Swaks documentation, but the key things to know are:
- Lines that end in
>
were sent to the server - Lines that begin in
<
were received from the server - Lines containing
*
are unexpected values or error messages
For example, trying to use incorrect credentials might return an authentication error like this:
~> AUTH PLAIN AG1haWxjcmVkZW50aWFsdXNlcgBtYWlsY3JlZGVudGlhbHBhc3N3b3Jk
<~* 535 5.7.8 Authentication failed
*** No authentication type succeeded