Troubleshooting SMTP servers with Swaks

Sometimes it can be difficult when you're configuring your application to send emails using SMTP. Your email library of choice is sending a weird error code or maybe no error message is shown at all when it should have.

As SMTP authentication is very primitive it is possible to test your settings using Telnet, but it can be a bit repetetive repeating the procedure every time it doesn't work out.

Fortunately there exists a tool written by John Jetmore for just this purpose. It is called Swaks and helps you to quickly identify problems with your configuration.

To quickly test an SMTP server with no encryption and no authentication you would use it like this:

./swaks --server mail.testserver.com  --to robin@hallabro.nu
=== Trying mail.testserver.com:25...
=== Connected to mail.testserver.com.
<-  220 TESTSERVER.test.local Microsoft ESMTP MAIL Service ready at Wed, 27 May 2015 12:05:04 +0200
 -> EHLO hallabro.nu
<-  250-TESTSERVER.test.local Hello [109.74.5.152]
<-  250-SIZE 10485760
<-  250-PIPELINING
<-  250-DSN
<-  250-ENHANCEDSTATUSCODES
<-  250-AUTH
<-  250-8BITMIME
<-  250-BINARYMIME
<-  250-CHUNKING
<-  250-XEXCH50
<-  250 XSHADOW
 -> MAIL FROM:<root@hallabro.nu>
<-  250 2.1.0 Sender OK
 -> RCPT TO:<robin@hallabro.nu>
<-  250 2.1.5 Recipient OK
 -> DATA
<-  354 Start mail input; end with <CRLF>.<CRLF>
 -> Date: Wed, 27 May 2015 10:05:04 +0000
 -> To: robin@hallabro.nu
 -> From: root@hallabro.nu
 -> Subject: test Wed, 27 May 2015 10:05:04 +0000
 -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 ->
 -> This is a test mailing
 ->
 -> .
<-  250 2.6.0 <1694a05d-fe06-4005-be9c-b0fd60c3f020@TESTSERVER.test.local> [InternalId=59575] Queued mail for delivery
 -> QUIT
<-  221 2.0.0 Service closing transmission channel