LinuxCommandLibrary

swaks

Send and test email from command line

TLDR

Deliver a standard test email to user@example.com on port 25 of test-server.example.net

$ swaks [[-t|--to]] [user@example.com] [[-s|--server]] [test-server.example.net]
copy

Deliver a standard test email, requiring CRAM-MD5 authentication as user me@example.com. An "X-Test" header will be added to the email body
$ swaks [[-t|--to]] [user@example.com] [[-f|--from]] [me@example.com] [[-a|--auth]] [CRAM-MD5] [[-au|--auth-user]] [me@example.com] --header-X-Test "[test_email]"
copy

Test a virus scanner using EICAR in an attachment. Don't show the message DATA part
$ swaks [[-t|--to]] [user@example.com] --attach - [[-s|--server]] [test-server.example.com] [[-n|--suppress-data]] [path/to/eicar.txt]
copy

Test a spam scanner using GTUBE in the body of an email, routed via the MX records for example.com
$ swaks [[-t|--to]] [user@example.com] --body [path/to/gtube_file]
copy

Deliver a standard test email to user@example.com using the LMTP protocol via a UNIX domain socket file
$ swaks [[-t|--to]] [user@example.com] --socket [/var/lda.sock] --protocol [LMTP]
copy

SYNOPSIS

swaks [options]

PARAMETERS

--to address
    Recipient email address.

--from address
    Sender email address.

--server hostname
    SMTP server hostname or IP address.

--port port
    SMTP server port number (default: 25).

--header header:value
    Add a custom email header.

--body message
    Message body content.

--file path
    Send the contents of a file as the message body.

--attach path
    Attach a file to the email.

--auth method
    Authentication method (e.g., LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5).

--user username
    Username for authentication.

--password password
    Password for authentication.

--tls
    Enable TLS encryption.

--starttls
    Use STARTTLS to initiate TLS encryption.

--verbose
    Increase verbosity level for debugging.

DESCRIPTION

Swaks (Swiss Army Knife for SMTP) is a versatile command-line tool designed for testing, diagnosing, and troubleshooting SMTP servers. It allows users to craft and send custom SMTP messages, enabling detailed analysis of server behavior, authentication methods, and protocol compliance. With Swaks, one can simulate various email scenarios, verify email delivery, and identify potential issues in email infrastructure. It supports a wide range of options for customizing message headers, body content, attachments, and authentication credentials. This makes it an invaluable tool for system administrators, developers, and security professionals involved in managing and securing email systems. It has the possibility to set custom TLS versions, and protocols, and to disable or enable specific STARTTLS settings for debugging the SMTP connection.

CAVEATS

Swaks requires careful handling of sensitive information like usernames and passwords. Avoid storing passwords directly in scripts. Ensure proper network connectivity and firewall rules are configured to allow communication with the target SMTP server.

RETURN CODES

Swaks returns different exit codes depending on the success of the operation. A return code of 0 indicates success, while non-zero codes typically indicate errors such as connection failures, authentication failures, or other issues during the SMTP transaction.

EXAMPLE USAGE

Sending a simple email:
swaks --to recipient@example.com --from sender@example.com --server mail.example.com --body 'This is a test email.'

Sending an email with authentication:
swaks --to recipient@example.com --from sender@example.com --server mail.example.com --auth LOGIN --user username --password password --body 'This is a test email with authentication.'

HISTORY

Swaks has evolved over time to incorporate various SMTP authentication mechanisms, TLS/SSL encryption support, and features for fine-grained control over email message construction. It's commonly used in automated testing and monitoring environments to verify the reliability of email services.

SEE ALSO

sendmail(1), mail(1)

Copied to clipboard