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
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
Test a virus scanner using EICAR in an attachment. Don't show the message DATA part
Test a spam scanner using GTUBE in the body of an email, routed via the MX records for example.com
Deliver a standard test email to user@example.com using the LMTP protocol via a UNIX domain socket file
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.