How to check SMTP Health on Linux?

SMTP stands for Simple Mail Transfer Protocol. It is an Internet standard communication protocol for email transmission across IP networks. SMTP is used to send messages from an email client to an email server or between servers. It operates on the application layer of the TCP/IP protocol suite and uses port 25 by default, though it can also use port 587 for messages submitted by email clients to servers and port 465 for secure communication over SSL/TLS.

The primary purpose of SMTP is to set up communication rules between servers, enabling them to relay email messages to the correct destination. SMTP handles the sending part of the email delivery process, while the receiving side typically involves additional protocols like IMAP (Internet Message Access Protocol) or POP3 (Post Office Protocol version 3) for email retrieval and management by the end user.

Monitoring SMTP  on Linux can be approached through various methods, including command-line tools, logging, and network monitoring tools. Here are some examples to get you started:

1. Using telnet or nc (netcat)

You can manually test an SMTP server’s responsiveness and simulate sending an email using telnet or nc. This method allows you to directly interact with the SMTP server.

telnet smtp.example.com 25

Or using nc:

nc smtp.example.com 25

You then follow the SMTP protocol steps manually (HELO, MAIL FROM, RCPT TO, DATA, etc.).

2. Using swaks

Swaks (Swiss Army Knife for SMTP) is a versatile, scriptable tool that can test various aspects of SMTP servers, including TLS/SSL support, authentication, and custom headers.

swaks --to [email protected] --from test@example.com --server smtp.example.com

3. Monitoring with tcpdump

tcpdump is a network packet analyzer that allows you to capture and display the TCP/IP packets being transmitted or received over a network to which the computer is attached. This can be used to monitor SMTP traffic.

tcpdump -i any port 25 -A

4. Using logwatch or logcheck

These tools can monitor your SMTP server logs for you, summarizing and highlighting important events. logwatch and logcheck can be configured to send daily summaries or alerts based on specific log patterns, which is useful for spotting issues or understanding usage patterns.

5. Setting up Nagios or Zabbix

Both Nagios and Zabbix are powerful monitoring systems that can be set up to monitor SMTP services. They can check SMTP server availability, queue lengths, round-trip email delivery, and more, providing alerts and detailed reports. It is very time and resources consuming to configure such self-hosted monitoring tools, which requires also a lot of maintenance and work in the same time, therefore we suggest you to use SMTP Monitoring of Xitoring, which will do the monitoring in package for you.

6. Using iftop or nethogs

For real-time network usage monitoring, iftop and nethogs show the bandwidth usage on the interfaces. While they don’t monitor SMTP specifically, they can be useful to identify unusual levels of network activity that might indicate an issue with your SMTP server.

Monitoring SMTP effectively often involves a combination of these tools and methods to ensure the server is performing as expected, secure, and not being abused for spam.