Installation

swaks (the “Swiss Army Knife for SMTP”) is a single Perl script and ships in every common package repository:

# Rocky, Alma, RHEL (EPEL), Fedora dnf install swaks # Debian, Ubuntu apt install swaks # macOS brew install swaks

TLS additionally needs Net::SSLeay (perl-Net-SSLeay or libnet-ssleay-perl). swaks --support shows what your installation can do — if “TLS supported” is missing, every test with --tls fails.

Reading the output

swaks logs the entire dialogue. The characters at the start of each line tell you who is speaking:

-> sent by swaks <- server reply ~> sent, inside TLS <~ reply, inside TLS <** error reply (4xx/5xx) === information from swaks *** error in swaks itself

Once the arrows turn into tildes after STARTTLS, the connection is encrypted.

First test: accept without sending

With --quit-after RCPT swaks stops after the recipient. The server says whether it would take the mail — but nothing is delivered:

swaks --server mail.yourdomain.com --helo client.yourdomain.com --from test@example.org --to info@yourdomain.com --quit-after RCPT

--helo almost always belongs there: without it swaks often cannot determine its own hostname and aborts with Helo string required. And many receivers reject a HELO that is not a fully qualified hostname.

If you leave out --server, swaks looks up the recipient domain's MX itself. Outbound port 25 is blocked on many residential and mobile connections — the attempt then ends in a timeout, and the test belongs on a server.

Checking STARTTLS and the certificate

swaks --server mail.yourdomain.com --helo client.yourdomain.com --to info@yourdomain.com --tls --tls-verify --quit-after TLS
  • --tls requires STARTTLS and aborts if the server does not offer it. --tls-optional merely tries.
  • --tls-verify checks chain and hostname (swaks 20240103 and later). On success it reports passed CA verification, passed host verification.
  • --tls-get-peer-cert additionally prints the server certificate as PEM.
  • --tls-protocol tlsv1_2 forces a specific version — a way to check whether the server still accepts it.

The line TLS started with cipher TLSv1.3:TLS_AES_256_GCM_SHA384:256 names version, cipher suite and key strength; below it the chain follows as TLS peer[0], peer[1] … with subject, SAN and expiry date.

Submission with login (ports 587 and 465)

swaks --server smtp.yourprovider.com --port 587 --tls --auth LOGIN --auth-user you@yourdomain.com --from you@yourdomain.com --to target@example.org --auth-hide-password swaks --server smtp.yourprovider.com --port 465 --tls-on-connect --auth LOGIN --auth-user you@yourdomain.com --from you@yourdomain.com --to target@example.org --auth-hide-password

Port 587 starts in plaintext and upgrades via STARTTLS (--tls); port 465 speaks TLS from the very first second (--tls-on-connect). Mixing them up gets you a timeout or 530 Must issue a STARTTLS command first.

Without --auth-password swaks prompts for the password — so it never lands in your shell history. --auth-hide-password masks it in the output too: otherwise the AUTH line contains it Base64-encoded, which is plaintext for anyone you show the log to. A failed login shows up as 535 5.7.8 Authentication credentials invalid.

Is the server an open relay?

A mail server may only accept mail for foreign domains from authenticated users. The test: foreign sender, foreign recipient, no login.

swaks --server mail.yourdomain.com --helo client.example.org --from test@example.org --to someone@example.net --quit-after RCPT correct: <** 554 5.7.1 <someone@example.net>: Relay access denied open relay: <- 250 2.1.5 Ok

A 250 at this point means anyone on the internet can send spam through the server, and the next blacklist listing is a matter of hours. What the rejection normally means is covered under 554 5.7.1 Relay access denied.

Does the recipient exist?

The same setup with a real domain but an invented mailbox:

swaks --server mail.yourdomain.com --helo client.example.org --from test@example.org --to doesnotexist@yourdomain.com --quit-after RCPT

A properly configured server rejects here with 550 5.1.1 User unknown. If it accepts, it later sends a bounce to a sender who never sent the mail — backscatter, and a reason for listings.

A real test mail with subject, body and attachment

swaks --server smtp.yourprovider.com --port 587 --tls --auth LOGIN --auth-user you@yourdomain.com --auth-hide-password --from you@yourdomain.com --to target@example.org --h-Subject "Test from $(date +%F)" --body "Test message" --attach @invoice.pdf
  • --h-Subject sets a header; any other works the same way (--h-Reply-To) or via --add-header "X-Test: 1".
  • An @ in front of a filename reads the content from that file — for --attach as well as --body.
  • --dump-mail shows the finished message beforehand without sending it.

Sending the test mail to AnalyzeMy.Email

Send the test mail to hello@analyzemy.email — through your real outbound server, i.e. with --server, port 587 and login as above. The reply covers SPF, DKIM, DMARC, the TLS path and blacklist status. Sent straight from a laptop to our MX, SPF fails by necessity: the report then examines your laptop, not your mail server.

Verify your work

A test mail through your mail server to hello@analyzemy.email shows how it looks from outside: TLS path, SPF, DKIM, DMARC and blacklists in one report.

Analyze your email now

Last updated: · All guides