|Don't ask to ask, just ask|
Postfix: Piping an email into a PERL scriptby Zzenmonk (Sexton)
|on Apr 26, 2013 at 13:45 UTC||Need Help??|
I spend today reading about how to pipe a mail received by postfix into a perl script. I read a lot but could hardly find a solution for my setup. So I give one here.
An application must be able to process email coming in from the net and it must be also able to respond to these emails.
The postfix main.cf configuration created by dpkg-reconfigure postfix
As usual TIMTOWTDI but a simple alias will NOT work! My solution works without:
Now you have to:
Modifications to the main.cf configuration
To avoid creating whatsoever users, we will use a kind of redirect. So we add a line like the following to the main.cf file:virtual_alias_maps = hash:/etc/postfix/redirect
Notice the hash: prefix to the file. This works well and avoid to re-compile postfix with pcre, in case it is not included.
Creation of the redirect map
Create the file defined above and enter a line with a regexp and a name in it:/[name]@[machine domain]/ [alias name]
Notice you have to use a regexp as first argument on this line! The alias name does not matter. Only secure name@domain is the correct email address.
Creation of the alias
Now we create the alias which will pipe the email into our script. Add a line like the following to the /etc/aliases file:[alias name]: "|/usr/bin/perl /[path to]/thescript.pl"
Notice you have to secure both alias name match!
Activate the whole thing
To activate all this you have to
This is what you will get in the STDIN of your script
Notice: If you intent to open(OUT ">", $filename); in your PERL script it will fail with a missing privilege error. To avoid this you have to set default_privs = to an other user than nobody in the postfix main.cf. This has impact on the whole postfix setting. I did not analyse it until now. So if you do this, you do it at your own risk.
The best medicine against depression is a cold beer!