LinuxCommandLibrary

swaks

Swiss Army Knife for SMTP testing

TLDR

Send a test email to a server
$ swaks -t [user@example.com] -s [mail.example.com]
copy
Send with SMTP authentication
$ swaks -t [user@example.com] -s [mail.example.com] -a LOGIN -au [username] -ap [password]
copy
Send with a custom subject and body
$ swaks -t [user@example.com] --header "Subject: [Test]" --body "[Hello World]"
copy
Send with an attachment
$ swaks -t [user@example.com] --attach [path/to/file]
copy
Send using STARTTLS encryption
$ swaks -t [user@example.com] -s [mail.example.com] --tls
copy
Send using implicit TLS (SMTPS on port 465)
$ swaks -t [user@example.com] -s [mail.example.com] --tls-on-connect -p 465
copy
Test via UNIX socket with LMTP protocol
$ swaks -t [user@example.com] --socket [/var/lda.sock] --protocol LMTP
copy
Set a custom EHLO/HELO greeting
$ swaks -t [user@example.com] -s [mail.example.com] --helo [myhost.example.com]
copy

SYNOPSIS

swaks [OPTIONS]

DESCRIPTION

swaks (Swiss Army Knife SMTP) is a featureful, scriptable SMTP test tool for diagnosing mail server configurations, testing authentication, and verifying email delivery. It supports SMTP, ESMTP, and LMTP protocols over various transports including TCP sockets, UNIX sockets, and TLS connections.
The tool is invaluable for testing spam filters (using GTUBE), virus scanners (using EICAR), authentication mechanisms, and TLS configurations. It provides detailed transaction logging showing each step of the SMTP conversation.

PARAMETERS

-t, --to address

Recipient email address. Can be specified multiple times.
-f, --from address
Sender email address.
-s, --server host
SMTP server hostname or IP.
-p, --port port
SMTP port (default: 25, or 465 with --tls-on-connect).
-h, --helo string
String to use as the HELO/EHLO greeting.
-a, --auth type
Authentication type (PLAIN, LOGIN, CRAM-MD5, DIGEST-MD5, NTLM).
-au, --auth-user user
Authentication username.
-ap, --auth-password pass
Authentication password.
--auth-optional
Attempt authentication but continue if unavailable.
-d, --data data
Use argument as the entire DATA portion of the message.
--body text
Message body content or file path.
--header header
Add a header to the message (e.g., "Subject: Test").
-ah, --add-header header
Add an additional header without replacing defaults.
--attach file
Attach a file to the message. Can be used multiple times.
--tls
Require STARTTLS encryption after connecting.
--tls-on-connect
Use implicit TLS (SMTPS) from the start of the connection.
--tls-verify
Verify the server's TLS certificate.
--tls-cert file
Client TLS certificate file.
--tls-key file
Client TLS private key file.
--socket path
Connect via UNIX domain socket.
--protocol proto
Protocol to use: SMTP, ESMTP (default), LMTP.
-n, --suppress-data
Don't show the DATA portion in output.
-q, --quit-after stage
Quit after the specified stage (CONNECT, EHLO, AUTH, MAIL, RCPT).
--timeout seconds
Connection and read/write timeout.
-4
Force IPv4 connection.
-6
Force IPv6 connection.
--dump
Display all options as interpreted and exit.

CAVEATS

Requires Perl. Passwords on command line are visible in process listings; use --auth-password-optional or a config file for sensitive data. Some authentication methods require additional Perl modules. Test emails may trigger spam filters.

HISTORY

swaks was created by John Jetmore and has been actively maintained since the early 2000s. It has become a standard tool for mail server administrators and is available in most Linux distribution repositories. The tool is written in Perl and released under GPLv2.

SEE ALSO

sendmail(8), postfix(1), openssl(1), curl(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard