What I'd like to do is set up an address like [email protected] which will take whatever email it gets and run the full message as STDIN into a shell script. I can't seem to get this working though. Tried a couple solutions, including this one:
How can I route some emails to a script in Postfix?
But my setup is a bit different. I've got the Postfix/Dovecot/MySQL setup, so all email is handled by Dovecot, and Postfix reads its maps from MySQL. Whatever I add to master.cf doesn't seem to work. SpamAssassin has a line in there and that's working fine. I'm stuck!
EDIT: I really wish people would read carefully before downvoting my question. I am using MySQL for my alias maps, so /etc/aliases does not work, I already tried that of course.
Obviously will work Douglas Land's answer, with a little addition.
Suppose you have only localhost.localdomain at $mydestination in main.cf.
Then add a virtual alias :
In main.cf you will need:
Then add to /etc/aliases :
newaliases+postfix reload and you are good to go.
You can pipe an entry to a script via
/etc/aliases
, RE:modify
/etc/aliases
then runnewaliases
and reload the postfix process.I'd go with Procmail. We use this to parse all sorts of mail out to worker scripts and IRC bots for notifications.
Here is an example of how to handle email. http://linuxgazette.net/issue14/procmail.html
Relevant short example done here for ease:
Create a local user called
handler
, for example.Go to
handler
's home directory and create a file called.procmailrc
containing:This will pass the entire inbound email to the script
$HOME/bin/my.script
through STDIN.Also here is where I got help with Procmail when I was first trying to pass email to a script: How to use procmail to get a message into a variable
I would check if sieve supports piping to a script. Dovecot supports sieve scripts.
As alternative you can use "procmail" as MDA between postfix an dovecot. Procmail can pipe to a script.
(that said I wonder why Douglas Land's answer does not work, mysql as backend should not make a different?!)"
Something that hasn't been mentioned is that you can use more than one lookup table (separated by comma or space):
The first one (virtual_alias_maps), will search for an email and return a username (for example: [email protected] -> info1234).
Then, the second one (alias_maps) will search for a username in your database, if not found, will search it at /etc/aliases. This way, you can still manage your aliases in MySQL and set your scripts in /etc/aliases, and no need to append "@localhost.localdomain" to the local users.
To test if your setup is correct, use:
Using Local accounts with aliases in MySQL:
In one of my custom setups, I'm using local accounts for users and MySQL for aliases only. So this is how I set it:
As you can see, feel free to mix them anyway you want.