2

I need to implement solution on my postfix/dovecot server which will execute bash script every time message arrives. For this purpose I did following things in master.cf configuration

myhook        unix  -       n       n       -       -       pipe
    flags=F user=customUser argv=/path/to/script.sh ${sender} ${recipient}

smtp      inet  n       -       -       -       -       smtpd
    -o content_filter=myhook:dummy

Works fine as long as you don't want to emails being delivered to mailboxes via dovecot. The problem is, that somehow I need to 'throw' back everything to dovecot. Or maybe there is a better approach, which is not known by me.

I appreciate every idea or tip in this case.

3 Answers 3

3

Your script must act like Simple content filter example from Postfix official documentation. After postfix send the email via pipe, you must resubmit it via sendmail command. Snippet from that page

Postfix receives unfiltered mail from the network with the smtpd(8) server, and delivers unfiltered mail to a content filter with the Postfix pipe(8) delivery agent. The content filter injects filtered mail back into Postfix with the Postfix sendmail(1) command, so that Postfix can deliver it to the final destination.

1

Normally, you'll want to re-inject your messages back into postfix from your script, instead of using a content filter, I think a before queue milter might be a better fit for your use case.

1

I solved the problem with creating 'own' delivery script. In fact, dovecot's deliver script is still used and is inside my own one, but before delivering message to mailbox, my script does stuff which I want to achieve. Of course I had to change 'virtual_transport' in main.cf vonfiguration as well as create hook in master.cf file (as I described in the question).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .