S
S
Sam Stay2018-07-11 17:31:55
linux
Sam Stay, 2018-07-11 17:31:55

How to execute your script when an email arrives in postfix?

Guys, tell me, please, how to execute your script when a letter arrives in postfix and at the same time deliver a message to the recipient?
Now it turned out to make it work out the script upon receipt, but the letter does not reach the mailbox.
master.cf

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

trigger   unix  -       n       n       -       -       pipe
    flags=F user=vmail argv=/etc/postfix/trigger ${sender} ${size} ${recipient}

"/etc/postfix/trigger" is a bash script that writes incoming parameters to a file for the time being.
This results in the following in the log:
postfix/qmgr[24500]: 41A1F434B96: from=<[email protected]>, size=608, nrcpt=1 (queue active)
postfix/pipe[24513]: 41A1F434B96: to=<[email protected]>, relay=trigger, delay=0.06, delays=0.03/0.02/0/0.01, dsn=2.0.0, status=sent (delivered via trigger service)
postfix/qmgr[24500]: 41A1F434B96: removed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sam Stay, 2018-07-11
@savenko_egor

Found a solution. Oddly enough, in the official documentation: Postfix After-Queue Content Filter
UPDATE 02/07/2020 :
Contribution to the future =)
If the construction above does not work, it is possible that the connection is made not on port 25, but on 465 or 587. In this case processing will be performed not by smtp, but by smtps or submission. If so, then the trigger call rule should be added to the smtps or submission sections.
UPDATE 02/20/2020 :
If spamassassin is added, then the trigger must be pulled from the spamassassin call, that is, like this:

spamassassin unix -     n       n       -       -       pipe
  user=spamd argv=/usr/bin/spamc -p 8730 --max-size 10240000 -f -e /etc/postfix/trigger -f ${sender} -- ${recipient}

In this case, the trigger call must be removed and only the spamassassin call should be left: Before
:
smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=trigger:dummy

It became:
smtp      inet  n       -       n       -       -       smtpd
  -o content_filter=spamassassin

V
Vladimir, 2018-07-11
@MechanID

a couple of options that came to mind:
1 copy the letter through virtual or aliases to 1 more address and the script will accept it there.
2 make a filter that hurts the script and the corresponding entry in the access file so that the filter is applied only to the desired address.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question