7

What I'd like to do is set up an address like something@myhost.com 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.

5 Answers5

4

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 :

something@myhost.com -> somelocaluser@localhost.localdomain

In main.cf you will need:

alias_maps=hash:/etc/aliases

Then add to /etc/aliases :

somelocaluser: "|/your/script/here"

newaliases+postfix reload and you are good to go.

1

You can pipe an entry to a script via /etc/aliases, RE:

foo: "|/your/script/here"

modify /etc/aliases then run newaliases and reload the postfix process.

sanmai
  • 561
1

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:

  1. Create a local user called handler, for example.

  2. Go to handler's home directory and create a file called .procmailrc containing:

:0
| $HOME/bin/my.script

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

SimonJGreen
  • 3,285
0

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?!)"

0

Something that hasn't been mentioned is that you can use more than one lookup table (separated by comma or space):

virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
alias_maps = mysql:/etc/postfix/mysql-aliases.cf hash:/etc/aliases

The first one (virtual_alias_maps), will search for an email and return a username (for example: info@example.com -> 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:

postmap -q info@example.com mysql:/etc/postfix/mysql-virtual.cf
postmap -q info1234 mysql:/etc/postfix/mysql-aliases.cf hash:/etc/aliases

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:

virtual_alias_maps = hash:/etc/postfix/vusers
smtpd_sender_login_maps = hash:/etc/postfix/vusers
virtual_alias_domains = /etc/postfix/vhosts
alias_maps = mysql:/etc/postfix/mysql-aliases.cf hash:/etc/aliases

As you can see, feel free to mix them anyway you want.

lepe
  • 469
  • 2
  • 8
  • 25