How to trigger a script based on header

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to trigger a script based on header

Quasar
Hi there,
I need some help, tried to find the answer googling for it, but no luck.
Here's my question: I'd need to trigger a script whenever an email is processed and sent. This trigger should be based on some header fields (e.g. subject).
I tried playing with header_checks but without getting anything.
Can you please help me?

Thanks
Giuseppe.
Reply | Threaded
Open this post in threaded view
|

RE: How to trigger a script based on header

angelo

Hi, AFA I know there is the “argv” parameter in master.cf that can run scripts you create, there may be others.

 

This is my test config:

 

autoreply unix  -       n       n       -       -       pipe

        flags=DF        user=nobody

        argv=/usr/local/bin/angelo $sender $recipient $original_recipient $user  $mailbox

 

 

And here is the script:

 

[root@mta5 ]# more /usr/local/bin/angelo

#!/usr/bin/bash

 

 

/usr/sbin/sendmail -oi -t <<EOF

From: UConn Help Center <[hidden email]>

To: $1

Subject: Your email to $3 was delivered

Content-Type: text/plain; charset=utf-8

 

This is a test email.

This is a notice to inform you that in the future when you send emails

to $3 they will fail to send.

Please send all future emails to users  @uconn.edu address.

Thank you.

 

 

this is 2 = $2

this is 1 = $1

this is 3 = $3

this is user = $4

this is mailbox = $5

 

 

And i recall only adding this to main.cf

 

transport_destination_recipient_limit = 1

 

and in virtual

@uchc.edu               [hidden email], [hidden email]

 

 

You will likely get a more specific answers with more details about your scenario.

I do not know if header_checks is normal way to trigger a script, I never did it that way.

 

Good Luck.

 

 

 

-ANGELO FAZZINA

 

[hidden email]

University of Connecticut,  ITS, SSG, Server Systems

860-486-9075

 

From: [hidden email] <[hidden email]> On Behalf Of Quasar
Sent: Wednesday, December 4, 2019 3:02 PM
To: [hidden email]
Subject: How to trigger a script based on header

 

Hi there,

I need some help, tried to find the answer googling for it, but no luck.

Here's my question: I'd need to trigger a script whenever an email is processed and sent. This trigger should be based on some header fields (e.g. subject).

I tried playing with header_checks but without getting anything.

Can you please help me?

 

Thanks

Giuseppe.

Reply | Threaded
Open this post in threaded view
|

Re: How to trigger a script based on header

Noel Jones-2
In reply to this post by Quasar
On 12/4/2019 2:01 PM, Quasar wrote:

> Hi there,
> I need some help, tried to find the answer googling for it, but no luck.
> Here's my question: I'd need to trigger a script whenever an email
> is processed and sent. This trigger should be based on some header
> fields (e.g. subject).
> I tried playing with header_checks but without getting anything.
> Can you please help me?
>
> Thanks
> Giuseppe.


Postfix doesn't do that directly, but there are several round-about
ways to make it work.

One incomplete example:
Set up an alias that pipes to your script.
aliases:
scriptuser: | /path/to/script

Use header_checks with a BCC action to send trigger mail to the
scriptuser
header_checks:
/^target text$/  BCC sciptuser@localhost

Note this requires localhost is listed in mydomains and is delivered
by the postfix local delivery agent.

Alternately, you can probably convince regex-milter to do this.



   -- Noel Jones
Reply | Threaded
Open this post in threaded view
|

Re: How to trigger a script based on header

Quasar
In reply to this post by angelo
Hi Angelo,
thanks for your quick reply.
I had a look at your solution, but I'd need a filter on the subject, not on sender or recipient. Can your solution be modified to include subject filtering as well?
Grazie :-)

On Wed, 4 Dec 2019 at 21:20, Fazzina, Angelo <[hidden email]> wrote:

Hi, AFA I know there is the “argv” parameter in master.cf that can run scripts you create, there may be others.

 

This is my test config:

 

autoreply unix  -       n       n       -       -       pipe

        flags=DF        user=nobody

        argv=/usr/local/bin/angelo $sender $recipient $original_recipient $user  $mailbox

 

 

And here is the script:

 

[root@mta5 ]# more /usr/local/bin/angelo

#!/usr/bin/bash

 

 

/usr/sbin/sendmail -oi -t <<EOF

From: UConn Help Center <[hidden email]>

To: $1

Subject: Your email to $3 was delivered

Content-Type: text/plain; charset=utf-8

 

This is a test email.

This is a notice to inform you that in the future when you send emails

to $3 they will fail to send.

Please send all future emails to users  @uconn.edu address.

Thank you.

 

 

this is 2 = $2

this is 1 = $1

this is 3 = $3

this is user = $4

this is mailbox = $5

 

 

And i recall only adding this to main.cf

 

transport_destination_recipient_limit = 1

 

and in virtual

@uchc.edu               [hidden email], [hidden email]

 

 

You will likely get a more specific answers with more details about your scenario.

I do not know if header_checks is normal way to trigger a script, I never did it that way.

 

Good Luck.

 

 

 

-ANGELO FAZZINA

 

[hidden email]

University of Connecticut,  ITS, SSG, Server Systems

860-486-9075

 

From: [hidden email] <[hidden email]> On Behalf Of Quasar
Sent: Wednesday, December 4, 2019 3:02 PM
To: [hidden email]
Subject: How to trigger a script based on header

 

Hi there,

I need some help, tried to find the answer googling for it, but no luck.

Here's my question: I'd need to trigger a script whenever an email is processed and sent. This trigger should be based on some header fields (e.g. subject).

I tried playing with header_checks but without getting anything.

Can you please help me?

 

Thanks

Giuseppe.



Reply | Threaded
Open this post in threaded view
|

RE: How to trigger a script based on header

angelo

Hi, to answer your question I messed around even though i don't think this is going to do it for you but it's a start.

 

master.cf

 

filter    unix  -       n       n       -       0      pipe

  -o syslog_name=postfix/trigg

  flags=Fq      user=filter

  null_sender= argv=/usr/local/bin/angelo  ${sender}  ${recipient}

 

header_checks

/^Subject: .*stuff.*/ FILTER filter:

/^subject:/ WARN

 

The major problem is i have not figured out how to deliver the original email that triggered the filter

in the first place.

 

here is logs of it working, and running my "angelo" script based on email subject

 

Dec  5 13:34:42 mta5 postfix/smtpd[1432]: connect from angelo.uits.uconn.edu[137.99.80.129]

Dec  5 13:34:43 mta5 postfix/smtpd[1432]: 092653000371: client=angelo.uits.uconn.edu[137.99.80.129]

Dec  5 13:34:43 mta5 postfix/cleanup[1438]: 092653000371: filter: header Subject: this is stuff in here from angelo.uits.uconn.edu[137.99.80.129]; from=<[hidden email]> to=<[hidden email]> proto=ESMTP helo=<[137.99.80.129]>: filter:

Dec  5 13:34:43 mta5 postfix/cleanup[1438]: 092653000371: message-id=<[hidden email]>

Dec  5 13:34:43 mta5 opendkim[1494]: 092653000371: DKIM-Signature field added (s=dkim1, d=mta5.uits.uconn.edu)

Dec  5 13:34:43 mta5 postfix/qmgr[1246]: 092653000371: from=<[hidden email]>, size=721, nrcpt=1 (queue active)

Dec  5 13:34:43 mta5 postfix/smtpd[1432]: disconnect from angelo.uits.uconn.edu[137.99.80.129]

Dec  5 13:34:43 mta5 postfix/trigg/pipe[1441]: 092653000371: to=<[hidden email]>, orig_to=<[hidden email]>, relay=filter, delay=0.17, delays=0.12/0.02/0/0.03, dsn=2.0.0, status=sent (delivered via filter service)

Dec  5 13:34:43 mta5 postfix/qmgr[1246]: 092653000371: removed

Dec  5 13:34:43 mta5 postfix/pickup[1245]: 2D3293000395: uid=1038 from=<filter>

Dec  5 13:34:43 mta5 postfix/cleanup[1438]: 2D3293000395: warning: header Subject: Your email to [hidden email] was delivered from local; from=<[hidden email]>

Dec  5 13:34:43 mta5 postfix/cleanup[1438]: 2D3293000395: message-id=<[hidden email]>

Dec  5 13:34:43 mta5 opendkim[1494]: 2D3293000395: DKIM-Signature field added (s=dkim1, d=mta5.uits.uconn.edu)

Dec  5 13:34:43 mta5 postfix/qmgr[1246]: 2D3293000395: from=<[hidden email]>, size=802, nrcpt=1 (queue active)

Dec  5 13:34:44 mta5 postfix/smtp[1446]: 2D3293000395: to=<[hidden email]>, relay=uconn-mail-onmicrosoft-com.mail.protection.outlook.com[104.47.55.110]:25, delay=1.7, delays=0.06/0.02/0.28/1.3, dsn=2.6.0, status=sent (250 2.6.0 <[hidden email]> [InternalId=20963735375625, Hostname=MWHPR05MB2973.namprd05.prod.outlook.com] 10746 bytes in 0.174, 60.000 KB/sec Queued mail for delivery)

Dec  5 13:34:44 mta5 postfix/qmgr[1246]: 2D3293000395: removed

 

But as you can see i don't understand Postfix well enough to make a proper script, or reroute to another Postfix instance as suggested in other threads from

my searching here http://postfix.1071664.n5.nabble.com/

 

Also i thought i could swap my script for the one in documentation here

http://www.postfix.org/FILTER_README.html

but i got a permission error.

 

Dec  5 13:27:05 mta5 postfix/qmgr[29586]: 42D50300039A: from=<[hidden email]>, size=1518, nrcpt=1 (queue active)

Dec  5 13:27:15 mta5 postfix/trigg/pipe[1078]: 42D50300039A: to=<[hidden email]>, orig_to=<[hidden email]>, relay=filter, delay=9057, delays=9047/0.02/

0/10, dsn=4.3.0, status=deferred (temporary failure. Command output: /usr/local/bin/trigger: line 21: in.1079: Permission denied Cannot save mail to file )

 

Sorry i can't be more helpful, good luck.

 

-ANGELO FAZZINA

 

[hidden email]

University of Connecticut,  ITS, SSG, Server Systems

860-486-9075

 

 

Hi Angelo,

thanks for your quick reply.

I had a look at your solution, but I'd need a filter on the subject, not on sender or recipient. Can your solution be modified to include subject filtering as well?

Grazie :-)

 

On Wed, 4 Dec 2019 at 21:20, Fazzina, Angelo <[hidden email]> wrote:

Hi, AFA I know there is the “argv” parameter in master.cf that can run scripts you create, there may be others.

This is my test config:

autoreply unix  -       n       n       -       -       pipe

        flags=DF        user=nobody

        argv=/usr/local/bin/angelo $sender $recipient $original_recipient $user  $mailbox

And here is the script:

[root@mta5 ]# more /usr/local/bin/angelo

#!/usr/bin/bash

/usr/sbin/sendmail -oi -t <<EOF

From: UConn Help Center <[hidden email]>

To: $1

Subject: Your email to $3 was delivered

Content-Type: text/plain; charset=utf-8

This is a test email.

This is a notice to inform you that in the future when you send emails

to $3 they will fail to send.

Please send all future emails to users  @uconn.edu address.

Thank you.

this is 2 = $2

this is 1 = $1

this is 3 = $3

this is user = $4

this is mailbox = $5