Rewriting the From: E-mail Header Using Sendmail and MIMEDefang
I frequently give out email addresses using <yourdomain@mydomain.com>; this way I am able to track the source of spam I receive. It also easily enables me to reject future email to that account by adding a line to sendmail‘s access file along with a “pleasant” 550 response message when warranted. My problem has been how to send an e-mail using that address.
The solution is quite simple – I specify the address in the Reply-To field of my e-mail client and use MIMEDefang to add an action to change the From: Header to the Reply-To: header.
Fortunately, I already had MIMEDefang added into the mix as I use it and SpamAssassin for processing mail. I had some difficulty understanding where and how to add the logic in the mimedefang-filter perl script but finally found useful information at http://www.mickeyhill.com/mimedefang-howto/ and through searching archives of the MIMEDefang mailing list.
I don’t have any users that use Reply-To and so the determination of when to apply this is quite simple; if the mail originated on the local LAN and the Reply-To header exists and has an email address then change the From header to the Reply-To contents and delete the Reply-To header. You may need to alter the contents of the if logic.
This is accomplished with the following code, placed near the end of sub filter_end:
# Rewrite From: header with Reply-To: if it exists
if ($RelayAddr =~ "^192\.168\.1\." && $entity->head->get('Reply-To') =~ /@/) {
action_change_header('From', $entity->head->get('Reply-To'));
action_delete_header('Reply-To');
}









