SMTP test with telnet

From time to time, it is handy to be able to test the ability of an email server to handle email as expected. Sometimes the best way is to directly interact with the email server itself.

To do that, you can use netcat, telnet or putty. Telnet is popular because it is already installed on most systems, but putty is very easy to use as well if you choose the telnet protocol and netcat (also nc) is often present on live (boot from CD or thumb drive) systems.

telnet new.smtpserver.com 25

ehlo example.com

MAIL FROM senderemail@example.com

RCPT receiveremail@example.com

DATA

Subject: this is a test message

[Press Enter Twice]

Hello. This message was sent through the SMTP server directly.

See also:

Another example, this one for sending from a command line through sendmail:

from: http://stackoverflow.com/questions/1333097/how-to-send-a-html-email-with-the-bash-command-sendmail

( echo "From: ${from}"; echo "To: ${to}"; echo "Subject: ${subject}"; echo "Content-Type: text/html"; echo "MIME-Version: 1.0"; echo ""; echo "${message}"; ) | sendmail -t