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]

Delivery status notifications (DSNs)

An RFC 3464 DSN (Delivery Status Notification) is a standardized email bounce message, commonly used to tell a sender if a message was delayed, or failed. Sometimes it might be useful to send a test DSN directly to a particular server.

Whenever an SMTP transaction is used to send a DSN, the MAIL FROM command should use a NULL return address, i.e., MAIL FROM:<>, this can be done by passing -f '<>' to swaks.

swaks -f '<>' -t [email protected] --data ./dsn.txt -s smtp.example.com

Example dsn.txt

Date: Thu, 7 Jul 1994 17:16:05 -0400
From: Mail Delivery Subsystem <[email protected]>
Message-Id: <[email protected]>
Subject: Returned mail: Cannot send message for 5 days
To: <[email protected]> 
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
        boundary="RAA14128.773615765/CS.UTK.EDU"

--RAA14128.773615765/CS.UTK.EDU

The original message was received at Sat, 2 Jul 1994 17:10:28 -0400
from root@localhost

    ----- The following addresses had delivery problems -----
<[email protected]>  (unrecoverable error)

----- Transcript of session follows -----
<[email protected]>... Deferred: Connection timed out
            with example.com.
Message could not be delivered for 5 days
Message will be deleted from queue

--RAA14128.773615765/CS.UTK.EDU
content-type: message/delivery-status

Reporting-MTA: dns; cs.utk.edu

Original-Recipient: rfc822;[email protected]
Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.7.1
Diagnostic-Code: smtp; 571 Delivery not authorized, message returned
Last-Attempt-Date: Thu, 7 Jul 1994 17:15:49 -0400

--RAA14128.773615765/CS.UTK.EDU
content-type: message/rfc822

[original message goes here]

--RAA14128.773615765/CS.UTK.EDU--

Feedback reports

RFC 5965 provides an abuse reporting format (ARF) that may be used by mail operators to report feedback about received email to other parties.

swaks -f [email protected] -t [email protected] --data ./fbl.txt -s smtp.example.com

Example fbl.txt

From: <[email protected]>
Date: Thu, 8 Mar 2005 17:40:36 EDT
Subject: FW: Earn money
To: <[email protected]>
MIME-Version: 1.0
Content-Type: multipart/report; report-type=feedback-report;
    boundary="part1_13d.2e68ed54_boundary"

--part1_13d.2e68ed54_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

This is an email abuse report for an email message received from IP
192.0.2.1 on Thu, 8 Mar 2005 14:00:00 EDT.  For more information
about this format please see https://mipassoc.org/arf/.

--part1_13d.2e68ed54_boundary
Content-Type: message/feedback-report

Feedback-Type: abuse
User-Agent: SomeGenerator/1.0
Version: 1

--part1_13d.2e68ed54_boundary
Content-Type: message/rfc822
Content-Disposition: inline

Received: from mailserver.example.net
    (mailserver.example.net [192.0.2.1])
    by example.com with ESMTP id M63d4137594e46;
    Thu, 08 Mar 2005 14:00:00 -0400
From: <[email protected]>
To: <Undisclosed Recipients>
Subject: Earn money
MIME-Version: 1.0
Content-type: text/plain
Message-ID: [email protected]
Date: Thu, 02 Sep 2004 12:31:03 -0500

Spam Spam Spam
Spam Spam Spam
Spam Spam Spam
Spam Spam Spam
--part1_13d.2e68ed54_boundary--

Further reading