[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 “bayz.de”):

$ swaks -f someone@example.net -t liquidat@example.com

If you need more recipients, add them via comma:

$ swaks -f someone@example.net -t liquidat@example.com,testme@example.com

It gets more interesting if you change the “TO” to another domain, but send the mail via the server for “bayz.de” nevertheless. If that works for arbitrary domains, and if the mails are forwarded to these you have big problem: an open relay.

$ swaks -f someone@example.net -t liquidat@example.com --server mail.example.com

Or do you need to know if a certain recipient is actually available?

$ swaks -f someone@example.net -t liquidat@example.com --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 someone@example.net -t liquidat@example.com --body /path/to/gtube/file

The same is true for anti virus programs and the Eicar file:

$ swaks -f someone@example.net -t liquidat@example.com --body /path/to/eicar/file

But Swaks can also be used to test user authentication and tls:

$ swaks -tls --server example.com -f liquidat@example.com -t someone@example.net  -ao --auth-user=liquidat

And this can of course be used to test authentication between servers:

$ swaks -tls -s example.com -f someone@example.net -t liquidat@example.com --ehlo $(host $(wget http://automation.whatismyip.com/n09230945.asp -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 someone@example.net -t liquidat@example.com --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.

Short Tip: Changing the original time of a photo at cli level

920839987_135ba34fffSometimes it happens that you take photos with a camera, and realize right in the middle of your session that the time of the camera is totally offset. In such cases: just keep taking photos and make sure that you take a photo of a clock at some point. You can correct the time stamps later on in the shell, even processing multiple images at once.

Afterwards, download the images, check the actual time offset by comparing the photographed clock and the time and date given in that image, and use exiftool to correct the time stamps of the photo. For example, imagine you have to change the time by adding two hours and fifteen minutes, the cli command is:

$ exiftool -AllDates-='2:15' *.JPG

You can check the actual date of the image either by the usual GUI programs or on command line:

$ exiftool MyImage.jpg|grep Time
File Modification Date/Time     : 2011:11:03 13:00:39+01:00
Exposure Time                   : 1/100
Date/Time Original              : 2009:09:05 07:07:49

If you have to process a batch of pictures, you can just wrap a for loop around the command.