Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

piping bounce service to external program

492 views
Skip to first unread message

Brian Armstrong

unread,
Aug 22, 2013, 5:08:56 PM8/22/13
to
I am trying to set up postfix to send bounced messages to an external script
to log the bounce to an external logging service so that we can monitor
bounce rates to different recipient domains. I want to keep the default
bounce behavior intact, so bounce notices are still send to the original
sender.

I have been hunting and testing different configurations for 2 days and
haven't had success, yet, in figuring it out.

First I tried changing the bounce service to use a pipe command:
in master.cfg I changed to bounce service to this "bounce unix - n n - -
pipe flags=Fhq user=bouncelog argv=/usr/local/bin/bounches.sh ${sender}
${recipient}"

I found somewhere people recommending not to do this because it is a system
critical service. This also destroys the default bounce behavior, which I'm
trying to keep intact. It generated the following errors, but it is probably
not the right approach anyway:
smtp postfix/pipe[13243]: warning: unexpected attribute nrequest from bounce
socket (expecting: flags)
smtp postfix/pipe[13243]: warning: deliver_request_get: error receiving
common attributes


Next I tried a custom transport for bounce notification emails
in main.cfg
notify_classes = bounce
bounce_notice_recipient = bou...@domain.com

at the top of my transport map:
bou...@domain.com bounces:

in master.cfg:
bounces unix - n n - - pipe
flags=FXhq user=bouncelog argv=/usr/local/bin/bounces.sh ${sender}
${recipient}

I was sure to run `postmap /etc/postfix/transport` after making changes to
the transport and `postfix reload` after modifying config files.

This one appeared to be working, but it doesn't quite. It has a few issues.
${sender} ends up being "double...@smtp.domain.com" and ${recipient} is
"bou...@domain.com". I believe, however, by looking at the logs that this
issue is caused because the bounce_notify email is actually sent, then
bounces, and that bounce notification is the one that gets logged instead of
the original bounce. I haven't found what I'm doing wrong, but it seems to
not be the correct approach since I want to log the bounce not parse an
email about the bounce.


We have an ebook copy of "Postfix - The Definitive Guide". I've read
everything in it regarding bounces and pipes. I haven't found anything that
points me in the right direction or answers my questions.


I'm wondering if anyone on the list can point me to the right documentation
and give me some pointers as to what I'm missing and what I need to
correct/fix to get this working. I'm almost to the point just writing a
script that tails the maillog and parses any line with "status=bounced" or
"status=deferred" in it. I would like something a little more real-time and
fault tolerant, though, and I'd like to do it correctly.

Thanks in advance for your help!




--
View this message in context: http://postfix.1071664.n5.nabble.com/piping-bounce-service-to-external-program-tp60729.html
Sent from the Postfix Users mailing list archive at Nabble.com.

Wietse Venema

unread,
Aug 22, 2013, 5:24:18 PM8/22/13
to
Brian Armstrong:
> I am trying to set up postfix to send bounced messages to an external script
> to log the bounce to an external logging service so that we can monitor
> bounce rates to different recipient domains. I want to keep the default
> bounce behavior intact, so bounce notices are still send to the original
> sender.
>
> I have been hunting and testing different configurations for 2 days and
> haven't had success, yet, in figuring it out.

Configure the appropriate bounce-recipient and use a transport map
to pipe mail for that recipient into a script:

/etc/postfix/main.cf
notify_classes = bounce, ....
bounce_notice_recipient = us...@example.com
transport_maps = hash:/etc/postfix/transport

/etc/postfix/transport:
us...@example.com bounce-pipe:

/etc/postfix/master.cf
bounce-pipe .... pipe
flags=xxx user=yyy argv=/path/to/script

# postmap /etc/postfix/transport
# postfix reload

The bounce message contains the failed recipient (the Final-Recipient:
field) and the envelope sender (the X-Postfix-Sender: field). An
example of all this is at the end of ADDRESS_REWRITING_README.

Wietse

Brian Armstrong

unread,
Aug 22, 2013, 8:01:26 PM8/22/13
to
Wietse,

Thank you very much for your response. I'd mentioned that I'd tried this
approach in my first message. You are, however, correct.

I was misreading the maillog when I thought it was sending the message and
well as hitting my script. I need to look at the daemon/queue/service that
is logging the message instead of just assuming the to=<> field means that
it was going out over SMTP.

The thing I was missing, for history, are the following:

1) With this method, the command line arguments to the script are not the
original recipient; they are about the new recipient who is getting the
bounce notification (the bounce_notice_recipient). This seems obvious now,
after a break of a couple hours. After hitting my heads against it all
morning I was fairly numb.

2) The contents of the email are given to the script as standard input.
This is well document all over the internet, but - since I kept thinking of
this as the same as piping the bounce service - I missed the message
contents completely and was just focusing on the macros passing arguments to
the script.

Thanks for pointing out the fields that I need to look for! That made my
life significantly easier in this instance.

Your help has been invaluable!



--
View this message in context: http://postfix.1071664.n5.nabble.com/piping-bounce-service-to-external-program-tp60729p60732.html
0 new messages