How to use the command swaks (with examples)
- Linux
- December 25, 2023
Swaks is a versatile SMTP transaction tester that can be used for various purposes. It allows users to send test emails, authenticate with different methods, test antivirus and spam scanners, and use different protocols for email delivery. This article provides examples of using the swaks command for each of these use cases.
Use case 1: Deliver a standard test email
Code:
swaks --to user@example.com --server test-server.example.net
Motivation: This command is useful for quickly testing the email delivery to a specific recipient using a specified server.
Explanation:
--to user@example.com
: Specifies the intended recipient email address.--server test-server.example.net
: Specifies the server to which the email will be sent.
Example output:
=== Trying test-server.example.net:25...
=== Connected to test-server.example.net.
<- 220 test-server.example.net ESMTP server ready
-> EHLO localhost
<- 250-test-server.example.net
<- 250-PIPELINING
<- 250-SIZE 10240000
...
Use case 2: Deliver a test email with authentication and custom header
Code:
swaks --to user@example.com --from me@example.com --auth CRAM-MD5 --auth-user me@example.com --header-X-Test "test_email"
Motivation: This command is useful when testing email delivery with authentication and adding custom headers to the email.
Explanation:
--from me@example.com
: Specifies the sender’s email address.--auth CRAM-MD5
: Specifies the authentication method as CRAM-MD5.--auth-user me@example.com
: Specifies the username for authentication.--header-X-Test "test_email"
: Adds a custom header with the name “X-Test” and the value “test_email”.
Example output:
...
<- 250-AUTH CRAM-MD5 DIGEST-MD5 PLAIN
<- 250-AUTH=CRAM-MD5 DIGEST-MD5 PLAIN
...
-> AUTH CRAM-MD5
<- 334 ACTHMTU0OTEzMDg4OTgyOTguNzUyMjk5MTlAY29tPjljMDU5ZDAxNGUyZGViOGRhYTI4ZjYyY2JmYTRiNGI5
-> aHJlZjU0OGNkNzllNmQxMWRhMDIzNjA1OTVhZGQ2OTlhMDIzNjVkMWM5OWFlNjc4ZGMxMTU5ODQwNDIxMTA2
<- 235 Authenticated
-> MAIL FROM:<me@example.com>
...
Use case 3: Test a virus scanner using EICAR in an attachment
Code:
swaks -t user@example.com --attach - --server test-server.example.com --suppress-data path/to/eicar.txt
Motivation: This command is useful to test whether a virus scanner properly detects the EICAR test file as malicious.
Explanation:
-t user@example.com
: Specifies the recipient email address.--attach -
: Attaches the EICAR test file inline.--server test-server.example.com
: Specifies the server for email delivery.--suppress-data path/to/eicar.txt
: Specifies the path to the EICAR test file.
Example output:
...
-> DATA
<- 354 Enter mail, end with "." on a line by itself