Running a script for email received

Running a script for email received

Geoff Shang geoff at QuiteLikely.com
Tue Aug 12 12:58:55 IDT 2014


On Mon, 11 Aug 2014, Ori Idan wrote:

> I am trying to run a script when an email is received on my server.
> I tried what described here:
> http://blog.thecodingmachine.com/content/triggering-php-script-when-your-postfix-server-receives-mail
>
> But it invoked the script for all mails not mail to a specific user
> I tried the simplest thing of /etc/alias
> But got error: Recipient address rejected: User unknown in virtual alias
> table

/etc/aliases is used by the local delivery agent to deliver local mail. 
That is to say, it delivers mail to actual accounts on the same system and 
for addresses with domains listed in $mydestination.  If the mailbox isn't 
for an existing user or the domain is a virtual or relay domain, you will 
need to use virtual_alias_maps.

The above suggests that postfix is looking in virtual_alias_maps for the 
address to which you are sending.  Unfortunately, scripts can't be used as 
targets for virtual_alias_maps lookups.

You could alias a virtual address to a local address which is an alias for 
the desired command.  This is what Mailman does.  For example, if you have 
a mailing list called management for the domain example.com, Mailman's 
virtual_alias_maps table would contain an entry like this:

management at example.com		management

And Mailman's alias_maps file would contain:

management:             "|/var/lib/mailman/mail/mailman post management"

Note that there isn't an actual user called management on the system.

This is probably the easiest way to achieve this, there are probably other 
ways like setting up a transport which could be used to call the script as 
described in the post but might not be worth the hassle for just one user.

All this is pretty well described in the various Postfix manpages.  Feel 
free to ask for further clarification, this stuff takes a bit to get one's 
head around.

HTH,
Geoff.




More information about the Linux-il mailing list