How can I configure exim to run a script for each e-mail

2.1k views Asked by At

I need to run a shell script under exim that can read each incoming e-mail, optionally rewrites them and then continues sending the email.

And ideal solution would be analogous to UNIX pipes:

cat *incoming email* | **some-script.sh** | *back to exim processing*

I want the script to run very early, so that I can for example change the destination address.

Is this possible with Exim, and how?

1

There are 1 answers

0
Kondybas On

You can create the router that use pipe transport with your script on the other side of pipe:

begin routers
preprocessor:
    driver      = accept
    condition   = if{ !eq{$header_X-Preproceeded}{yes}}
    transport   = myscript
    no_more

. . . . .

begin transports
myscript:
    driver      = pipe
    user        = scriptowner
    command     = /path/to/script --opt1 --opt2

If incoming message does not have X-Preproceeded header or its value doesn't set to yes then message is passed to the myscript transport. That is performed via piping source | script and all the message is passed to the script's stdin. After proceeding if you want to return proceeded message to the exim, you should add the x-Preproceeded: yes header to the message to prevent it to be routed to the next lap. Then you have to submit it via sendmail command.

#!/bin/sh
. . . . 
mandatory_empty_line = ''
cat << ENDOFTEXT | /usr/sbin/sendmail -t
$headers
X_Preproceeded: yes
$mandatory_empty_line
$message_body
ENDOFTEXT

Keep in mind that effective user running script should be added to the trusted users by exim's config to allow sending from arbitrary address. Otherwise exim will replace any sender's address by [email protected]