DevHeads.net

Adding a dynamic header to all mail passing through Postfix

I am suffering from AOL numpties who click "this is spam" on
notification emails they get (by their request!) from a forum and
mailing list hosted on my server. In order to trap these, I've set up a
feedback loop with AOL so that I'm notified when anybody does that.

However, AOL's feedback system removes the recipient email address, so I
can't identify the complainer from the report. So what I need to do is
add a custom header to every outbound mail from my server which
identifies the recipient address.

Of course, one way to do this would be to set the header in the software
which generates the mail. But this is impractical for several reasons:
Firstly, there is more than one package on the server which sends mail,
so all of them would need to be changed, and, secondly, I didn't write
any of them so it not only means editing someone else's code but also
re-applying the edit any time I upgrade.

What I'd like to do, therefore, is set a header via Postfix. But I am
having difficulty working out how to do that, or even if it's possible.

I already have a line in main.cf for header checks:

header_checks = regexp:/etc/postfix/header_checks_regex

so I started from the assumption that I ought to be able to simply add a
line to that which matches everything and use that to add the header:

/./ PREPEND X-Test-Header: yes

Now, that works OK. But what I want to do is to be able to replace the
header value in each mail with a custom value derived from the mail
itself, using some kind of lookup or replacement method - something like

/./ PREPEND X-Test-Header: ${user}

So my question is: is there any way to do this? If so, how? Or am I
barking up completely the wrong tree here?

Mark

Comments

Re: Adding a dynamic header to all mail passing through Postfix

By Wolfgang Zeikat at 11/22/2011 - 10:03

In an older episode, on 2011-11-22 11:51, Mark Goodge wrote:
It does not remove your server's header lines though, including
message-ID and postfix queue ids, so you can find the information in
your outgoing server's logs.

Hope this helps,

wolfgang

Re: Adding a dynamic header to all mail passing through Postfix

By Mark Goodge at 11/22/2011 - 10:25

On 22/11/2011 14:03, Wolfgang Zeikat wrote:
Indeed, but that adds an extra layer of effort to the process, and isn't
always practical if a report comes in when I don't have direct access to
the server. If someone is stupid enough to sign up to a forum and then
hit the spam button when the forum sends them a notification, I just
want to delete their membership via the web interface without any extra
faffing around.

Mark

Re: Adding a dynamic header to all mail passing through Postfix

By Ralf Hildebrandt at 11/22/2011 - 10:04

* Wolfgang Zeikat <wolfgang. ... at desy dot de>:
Exactly.

Re: Adding a dynamic header to all mail passing through Postfix

By Wietse Venema at 11/22/2011 - 09:20

Mark Goodge:
First, you must send one recipient per message, otherwise you still
won't know who the recipient was when you get feedback from AOL.

Once you have one recipient per message, prepend the recipient with
check_recipient_access:

/etc/postfix/main.cf:
smtpd_XXX_restrictions =
check_recipient_access pcre:/etc/postfix/prepend.pcre

/etc/postfix/rcpt_prepend.pcre:
/(.+)/ prepend X-YYY: $1

For suitable values of XXX and YYY.

Or use VERP, as others have suggested.

Wietse

Re: Adding a dynamic header to all mail passing through Postfix

By Mark Goodge at 11/22/2011 - 09:23

On 22/11/2011 13:20, Wietse Venema wrote:
Thanks. I'll investigate both options, and see which is best suited to
my needs.

Mark

Re: Adding a dynamic header to all mail passing through Postfix

By Wietse Venema at 11/22/2011 - 09:53

Mark Goodge:
One more thing.

You can use the smtpd_command_filter feature to append XVERP to
SMTP commands from legacy sofware. This requires Postfix 2.7 or
later.

/etc/postfix/main.cf:
smtpd_command_filter = pcre:/etc/postfix/append_verp.pcre
smtpd_authorized_verp_clients = $mynetworks

/etc/postfix/append_verp.pcre:
/^(MAIL FROM:<listname@example\.com$>.*)/ $1 XVERP

I just added this note to VERP_README.

Wietse

Re: Adding a dynamic header to all mail passing through Postfix

By Wietse Venema at 11/22/2011 - 12:41

Wietse Venema:
That "$" before ">" should be removed.

Wietse

Re: Adding a dynamic header to all mail passing through Postfix

By Ralf Hildebrandt at 11/22/2011 - 07:35

* Mark Goodge <mark@good-stuff.co.uk>:
Been there, done that

Simply make your lists use VERP and this problem is solved!

Re: Adding a dynamic header to all mail passing through Postfix

By Brian Evans - P... at 11/22/2011 - 09:53

On 11/22/2011 6:35 AM, Ralf Hildebrandt wrote:
In regards to the OP's issue for this case, AOL also will obfuscate a
VERP address in its report.
So a non-email based header may be the only option.

Re: Adding a dynamic header to all mail passing through Postfix

By Ralf Hildebrandt at 11/22/2011 - 09:54

Not enough :)
On python.org I still can identify the original recipients.

Re: Adding a dynamic header to all mail passing through Postfix

By Jerry at 11/22/2011 - 07:22

On Tue, 22 Nov 2011 10:51:27 +0000
Mark Goodge articulated:

Wouldn't VERP be what you are looking for?

<a href="http://www.postfix.com/VERP_README.html" title="http://www.postfix.com/VERP_README.html">http://www.postfix.com/VERP_README.html</a>