This script monitors Email Security Appliance (ESA)/Cloud Email Security (CES) or email SMTP server deliverability and send notification trap on email service unavailable. The monitoring period can be defined and default to 5min. The notification method is by SNMP trap. The script allows the use of python email library or swaks CLI tool.
The script was tested on ESA, and it should work on any compatible SMTP service.
v1.1 update (13th Dec 2025) - Added optional email notification module.
Before running the email deliverability check script, ensure the following modules and tools are installed and configured:
sudo apt-get install swaks
sudo apt-get install snmp
The script monitors email deliverability and handles these scenarios:
Configure Variables: Modify the following variables in the script as needed:
Install Dependencies: Install required tools and Python modules as per the prerequisites.
Permissions: Ensure the script has execution permissions and the user running it has rights to execute snmptrap and network commands.
Run the Script: Execute the script manually or schedule it with cron or another scheduler for continuous monitoring.
Normal Case: Run the script with a reachable SMTP server accepting connections on port 25. Confirm output similar to:
[YYYY-MM-DD HH:MM:SS] Email sent successfully.
Server Down Case: Test with an unreachable SMTP server IP or stopped mail service. The script should log failures and retry.
Brown-out Case: Test with the SMTP server IP reachable but port 25 closed or filtered. The script should detect failure and retry.
Failure Limit Exceeded: After exceeding retry limits, verify the script sends an SNMP trap. Confirm success message or error logs if snmptrap is missing or misconfigured.
SNMP Trap Command Validation: Ensure the send_snmp_trap() function uses the correct syntax with an empty agent address and valid variable bindings to avoid errors like "Bad variable type."
This documentation provides a clear overview for users to prepare, deploy, and test the email deliverability check script effectively, capturing key error scenarios and operational details.
Example on normal scenario when the script runs, the monitoring mailbox receive the email, the script sleeps till the next check cycle and keep repeating:-
Error scenario, the email service is not available, script triggers and sent SNMP trap:-
The bottom shows SNMP trap received at the SNMP server.
Scenario with SNMP + email notification, SNMP trap sent along with email notification to external mailbox:-
ESA - Cisco Email Security Appliance
CES - Cloud Email Security
Author: ciscoketcheon
License: BSD3
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community