Checking sendmail mail delivery from the command line

A user reported problems with email deliveries this morning, but when I checked the outgoing mail queue with the mailq command on the CentOS 7 server running sendmail, the queue was empty.
# mailq
/var/spool/mqueue is empty
		Total requests: 0

I tried sending a test message from the mail sever to an external email account with the mailx command. For the body of the message, I put some text into a file named test.txt and used the < character to provide the contents of the file as input to mailx for the body of the message. I didn't receive any error message and I didn't see any messages stuck in the mail queue when I checked it after I sent the message. But the message was not received at the destination email account.

# mailx -s "Testing" <test.txt
# mailq
/var/spool/mqueue is empty
		Total requests: 0

So I then used the sendmail command, instead, to send a test message to see if it would provide me with any information that I could use for troubleshooting the problem. I created a file with the following contents to send as a test message.

# cat temp.txt
Subject: Sendmail test

This is a test.
This is only a test.

You can send a test message whose contents are contained in a text file from a command line interface using a sendmail command in the form sendmail recipient_email_address < input_file. But when I did that, I saw a "Connection refused by []" message.

# sendmail < temp.txt
# sendmail -v < temp.txt Connecting to [] via relay... Deferred: Connection refused by []

You can also send a message with the content for the body of the message typed after you issue the command as shown below, though in this case, since there was a problem with sendmail, I received the "Connection refused by []" message. After you issue the command, you won't see a prompt, but you can type text for the body of the message. Hit Enter to start a new line in the message and hit Ctrl-D when you are finished entering text for the body of the message to send the message.

# sendmail -v
A test message.,Test,Message... Connecting to [] via relay...,Test,Message... Deferred: Connection refused by []

After I saw the "Connection refused by []" message, I checked to verify that sendmail was running by attempting to connect to the Simple Mail Transfer Protocol (SMTP) port, which is TCP port 25. The netstat command did not show any process listening for connections on that port. I also tried a Telnet connection to that port, which I expected to fail, since netstat wasn't showing any process listening on that port; I received a "connection refused" message when I attempted to connect to port 25 on the localhost address, But I did find that the system was listening on the Post Office Protocol version 3 (POP3) port, port 110, and on the secure POP3 port, port 995, aka the pop3s port.

# netstat -a | grep -i smtp
# telnet 25
telnet: connect to address Connection refused
# netstat -a | grep -i pop3
tcp        0      0 *               LISTEN     
tcp        0      0  *               LISTEN     
tcp6       0      0 [::]:pop3s              [::]:*                  LISTEN     
tcp6       0      0 [::]:pop3               [::]:*                  LISTEN     
unix  2      [ ACC ]     STREAM     LISTENING     1398391  /var/run/dovecot/login/pop3

The user who reported the problem to me told me that she normally gets a fair amount of spam, but this morning when she checked her email, though her email client didn't report any problems in checking email, she didn't receive any messages. Since Sendmail wasn't listening on port 25, though, no other email server would have been able to deliver email to the system, so no one on the system would have been receiving email from other email servers.

I started sendmail to resolve the problem and verified the system was then listening on the SMTP port.

# service sendmail start
Redirecting to /bin/systemctl start  sendmail.service
# netstat -a | grep -i smtp | head -n 1
tcp        0      0  *               LISTEN     

I then sent another test message with sendmail. I used the -v option to get verbose information regarding the transmission of the email. This time, after I hit Ctrl-D after typing some text for the body of the message, I saw much more information and the message was successfully sent to the recipient email address and I saw it in the inbox for the recipient account.

$ sendmail -v
Still testing. Connecting to [] via relay...
220 ESMTP Sendmail 8.14.7/8.14.7; Mon, 25 Jul 2016 11:43:11 -0400
>>> EHLO Hello localhost [], pleased to meet you
250 HELP
>>> MAIL From:<> SIZE=15
250 2.1.0 <>... Sender ok
>>> RCPT To:<>
>>> DATA
250 2.1.5 <>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 u6Q1S2a4011079 Message accepted for delivery Sent (u6Q1S2a4011079 Message accepted for delivery)
Closing connection to []
>>> QUIT
221 2.0.0 closing connection

I thought the system might have rebooted due to a recent brief power outage and that sendmail might not have restarted afterwards, but when I checked the date of the last reboot, I found it was weeks ago, so that wasn't the cause for sendmail not running.

$ last reboot | head -n 1
reboot   system boot  3.10.0-229.7.2.e Fri Jul  1 19:04 - 21:05 (24+02:00)  


TechRabbit ad 300x250

Justdeals Daily Electronics Deals1x1 px