ETRN client bash shell script recipe

by matthew
0 comment

I happened upon a need for an SMTP ETRN client, specifically to make a proxmox pve mail filtering system notify a backup postfix mail exchanger to despool using the ancient art of speaking ETRN.

It uses the ‘netcat’ package and reads the list of domains serviced by the local proxmox mail gateway, making the crass assumption the backup MX relays for the same domains along with hard coding the remote mail exchanger and smtp port.

Season to taste!

#!/bin/bash

function etrn()
{
        host=$1
        port=$2
        domain=$3
        
        ( sleep 1; echo ehlo `hostname`; echo etrn $domain; sleep 2; echo quit; sleep 1 ) | \
        ( nc $host $port ) 
}

DOMAINS=$( cat /etc/pmg/domains|awk -F ' ' '{print $1}')
for domain in $DOMAINS; do 
        etrn mxtwoish.example.com 25 $domain
done

(i thought about hacking up a quick script to do networking and proper response checking but opted to just select arbitrary sleeps and blindly hit the smtp server. maybe github has a real etrn tool already written. this works well enough for now along with queue management on the remote backup)