quickly check your mail server using telnet, mail or mutt

by jagbir on October 31, 2010

There are of course various ways to check whether your mail server is now configured ok or not but what I found is that checking through telnet is quick and easy.

let’s check our mail server now, it may be mail.youdomain.com or localhost depending on what you are using right now, here’s the full process:

# telnet localhost smtp
Connected to localhost.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix
mail from: me@example.com
250 2.1.0 Ok
rcpt to: other@example.com
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
Subject: Just a test. 
This is test mail using telnet.  
250 2.0.0 Ok: queued as 6846838401D6
221 2.0.0 Bye
Connection closed by foreign host.


# telnet localhost smtp

We are trying connecting localhost on port 25 (smtp). It should get connected and ready to accept your next command

mail from: me@example.com

here you are specifying the sender mail id, it should be a valid mail account otherwise mail server can reject the sender address.

rcpt to: other@example.com

This is the recipient mail address.
then write ‘data’ and then in new line write ‘Subject: your subject’, press Enter and start writing contents of your mail. when you want to close, write a dot (.) and press Enter. message should be sent/queued in mail queue.
Check the recipient mail address, if mail server is working ok, you should get this mail there.

Other than this method where you can quickly use mail command also, like this:

# echo "This is a test mail to check mail server." | mail - s "This is test subject" other@example.com

This is a single line command but alas! we didn’t supply sender here which may trigger rejection from mail server.

You can also use mutt tool to facilitate this, if its there in your machine, like this:

# mutt -s "Test mail" other@example.com < message.txt

here message.txt contains mail message.

Previous post:

Next post: