A simple script for quick Postfix system email management.
#!/bin/bash
RETVAL=0
case $1 in
count)
mailq | tail -n 1
;;
list)
COUNT=$(mailq | grep -c "^[A-F0-9]")
if [[ $COUNT -gt 5 ]]; then
postqueue -p | less
else
postqueue -p
fi
;;
show)
echo $2
postcat -q $2 | less
;;
flush)
postqueue -c /etc/postfix -f
;;
purge)
postsuper -d ALL
;;
start)
#systemctl start postfix
postfix start
;;
stop)
#systemctl stop postfix
postfix stop
;;
*)
echo "Usage: $0 {count|list|show|flush|purge|start|stop}"
mailq | tail -n 1
RETVAL=1
esac
exit $RETVAL