Friday, March 22, 2013

Howto: Sending test mails with Swaks

Setting up e-mail servers can become a time consuming and complex task. Test mails can help verifying the functionality of the system – and here Swaks comes into play, the “swiss army knife for smtp”.
Swaks can be used to send test mails of all kinds. The advantage of Swaks compared to sending mails with your normal e-mail client is that you are able to alter almost any part of the e-mail: to, from, header, attachments, which server to speak to, etc.
Here are some common Swaks usage examples:
The first, basic example is sending a mail to your own server (here “”):
$ swaks -f -t
If you need more recipients, add them via comma:
$ swaks -f -t,
It gets more interesting if you change the “TO” to another domain, but send the mail via the server for “” nevertheless. If that works for arbitrary domains, and if the mails are forwarded to these you have big problem: an open relay.
$ swaks -f -t --server
Or do you need to know if a certain recipient is actually available?
$ swaks -f -t --quit-after RCPT
But you can also use Swaks to test a spam filter: If any of the bigger spam filters out there identifies the GTube sting in an e-mail, it will mark it as spam:
$ swaks -f -t --body /path/to/gtube/file
The same is true for anti virus programs and the Eicar file:
$ swaks -f -t --body /path/to/eicar/file
But Swaks can also be used to test user authentication and tls:
$ swaks -t -tls --server -t -f -ao --auth-user=liquidat
And this can of course be used to test authentication between servers:
$ swaks -t -tls -s -f -t --ehlo $(host $(wget -O - -q))
The last bit makes sure your local test machine does provide a correct fqdn.
But in case your MTA setup does rely or use custom headers, how about adding some of these?
$ swaks -f -t --add-header "X-Custom-Header: Swaks-Tested"
If you have other interesting examples, don’t hesitate to drop them in the comments, I am happy to add them here.

No comments:

Post a Comment