So, it turns out this is pretty easy to do; attached is the postproc
wrapper I cooked up to send to different mail servers based on the
"From" address.  Of course, you could really use any algorithm you want;
this is just an example.  I can't claim this is perfect, but I think
it's a good first effort, and I've started to use it.  Hope this is
helpful for people!

--Ken
#!/bin/sh
#
# localpostproc - decide where to send email based on the draft message
#

realpost="$(mhparam libdir)/post"

if [ $# -eq 0 ]; then
	echo "Usage: [post switches] filename"
	exit 1
fi

eval draftmessage=\${$#}

fromhost=$(scan -format '%(host{from})' -file "$draftmessage")

if [ $? -ne 0 ]; then
	echo "Unable to run scan on draft file $draftmessage, aborting"
	exit 1
fi

if [ -z "$fromhost" ]; then
	echo "Could not determine hostname of From: address"
	exit 1;
fi

case "$fromhost" in
	*some.other.host)
	postflags="-server some.other.server -sasl -port submission"
	;;

	pobox.com)
	postflags="-server smtp.pobox.com -sasl -tls -port submission"
	;;

	*)
	echo "Don't know how to send email from $fromhost"
	exit 1
	;;
esac

exec "$realpost" $postflags "$@"
_______________________________________________
Nmh-workers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/nmh-workers

Reply via email to