This article will show two ways to test your SMTP server from the command line in Linux, these tests are very useful when setting up a new server and you just want to make sure you have it working before you continue on. Lets get started
In this first example we are going to test the server with no auth on port 25:
nc mail.agix.com.au 25
The above example is using netcat which is very useful in cases like this, now that we are connected to our server on port 25 using netcat we can start our test, in our below example we need to say EHLO to the domain that the server is serving mail for in our example agix.com.au
Now we need to tell it what sender address we are expecting to use, in this case it is [email protected]
mail from:[email protected]
Now we need to tell it where the mail needs to be delivered, this could be a local user or perhaps an external email.
rcpt to:[email protected]
And lastly we need to give it some data to put in the email, you can use special flags such as the ones below setting a To, From and Subject, these will show up in the users email client. For our example we are going to make the mail be from [email protected]
data To: null From: support Subject: SMTP connection test This is the body of the email. .
To finish this command type . and then hit enter once you have done so you will be told what the queue number is for your message and then you can just type quit to exit netcat.
Simple, if your server is working correctly then you should receive the email in your inbox and all is good, but what if your server requires authentication. Well that is where openssl client comes in, just follow the setups below:
First we need to create a base64 string containing our username and password. Be sure to leave the \0 characters in their place otherwise the command will not be formatted correctly. Just replace the username and password with yours.
AUTH_STRING="$(echo -en '\0brad\0lamepassword' | base64)"
Now we can go ahead and try to connect using the openssl client on the submission port 587 assuming that is what is in use.
openssl s_client -quiet -starttls smtp -crlf -connect mail.agix.com.au:587
Same deal as the last example we need to be polite and say EHLO,
The server in this example is not going to like talking to us without auth, in fact it won’t so lets go ahead and give it our auth string.
AUTH PLAIN $AUTH_STRING
Now we can do the same as last time, tell the server who from, who to and some data just like before.
mail from:[email protected] rcpt to:[email protected] data To: null From: support Subject: SMTP over STARTTLS with AUTH test Test .
As before just type quit to exit
That is it, pretty simple.