Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Testing Email Server Response

Submitted by on November 7, 2015 – 5:37 pm

A little while ago I ran into a situation when connections to the relay email server would occasionally time out. The issue seemed sporadic resulting in a controversy regarding its source. The perimeter email server would receive the emails, run a preliminary virus scan and forward the emails to the relay. From time to time the perimeter email server would log the “Lost connection while receiving initial greeting” error while trying to contact the relay.

Below is a simple script that uses the “expect” command to talk to the mail server and provides some additional information about the responses from the server that can be used for troubleshooting. Save the script to an executable script file and run it with the “time” command.

#!/bin/bash
d=$(date)
expect -c "spawn nc -vt <mail_server> 25;\
expect \"*succeeded*\";\
send \"helo <sender_domain>\r\";\
expect \"250 <mail_server>*\";\
send \"mail from: <sender_address>\r\";\
expect \"*Sender ok*\";\
send \"rcpt to: <recipient_address>\r\";\
expect \"*Recipient ok*\";\
send \"data\r\";\
expect \"*Enter mail*\";\
send \"From: 'Sender Name' <sender_address>\r\";\
send \"To: 'Recipient Name' <recipient_address>\r\";\
send \"Subject: test email\r\";\
send \"Date: ${d}\r\";\
send \"This is a test email\r\";\
send \".\r\";\
expect \"*Message accepted for delivery*\";\
send \"\r\";\
send \"quit\r\";\
expect \"*Closing connection*\";\
exit"

 

Print Friendly, PDF & Email

Leave a Reply