Testing SMTP creds with Docker

Mar 24, 2019 · 195 words · 1 minute read

One of our sites stopped sending it’s mail a few days ago. Unfortunately, the SMTP plugin used does not provide any debug logs of the SMTP connection, and it’s ’test’ tool just says that it sent the mail successfully. The logs for the SMTP service provider suggest they haven’t seen the connection. I issue a new password and reconfigure, still the same symptoms.

So, I just want to do a simple check of the new SMTP creds. I also wanted to use a simple tool to avoid having to recall (Google) the magic SMTP protocol incantations and perform them via ’telnet’ or whatever. The ‘ssmtp’ tool sprung to mind for some reason, so I figured I’d see how simple that would be to use in this case.

I fired up a disposable docker container to perform this in.

docker run --rm -ti alpine sh

Then, installed and configured ssmtp as follows:

apk -U add ssmtp
cat >/etc/ssmtp/ssmtp.conf <<EOF
Mailhub=smtp.mailserver.com:587
Hostname=mydomain.com
AuthUser=29a0ca06-ec73-488f-883e-f8bda2225a99
AuthPass=29a0ca06-ec73-488f-883e-f8bda2225a99
UseSTARTTLS=YES
EOF

Now I can send test mail like this:

echo "Test mail" | ssmtp -v you@yourdomain.com

The output will show the SMTP transaction, and ultimately whether or not the authentication was successful.