views:

680

answers:

2

I am using postfix in my production server which will receive all the emails related to mydomain.com In this context, I want to forward only emails related to few users to different email addresses. By which I mean, lets say I am a super user([email protected]). I want to forward all my emails(all mails with to:[email protected]) to my personal email id: [email protected]. So I think I would some programming logic is needed here. So I want to write a custom python script which should read the postfix email inbox and forward all new emails depending on the said criteria. Can I do this? I heard about .forward file in the postfix arena. Can I use that to achieve the same(by totally bypassing pythonic solution)?

A: 

Procmail is the solution for mail filtering. You can call python scripts from your .procmailrc if you need more scripting.

Anders Westrup
Assuming I call python script from .procmailrc, how will run my python logic on the current email/or in that case, on the total inbox. To be more specific, how do I get the context of firing the python program? By context I mean, Can I get the mail which was responsible for firing the python script?
Maddy
I got it. the mail message will be given as standard input to my python script. so the last line of .procmailrc file will be "| python privilege_emailer.py" right? But I tried this, and the python script is not running. May I know why?
Maddy
+3  A: 

It sounds like you just need to set up aliases, not script anything.

On most Unix/Linux systems, you simply add aliases to your /etc/aliases file:

superuser:                 marc,[email protected]

then run:

newaliases

Then mail sent to "superuser" would go to "marc" and "[email protected]" instead.

here's a tutorial, and here's the postfix 'aliases' man page.

Yoni Samlan
The example I have taken(superuser) is a bit misleading. Superuser is not unix system's super user. Its actually site(mydomain) user. So I will be receiving emails to anybody "@mydomain.com" at my production machine, and I need forward a few ones to their corresponding personal email ids.Now tell me
Maddy
Right -- suppose you want to forward the emails coming in to [email protected] to [email protected]. On the mail server for mydomain.com, you'd add "steven: [email protected]" to /etc/aliases, then run newaliases. That's all there is to it.
Yoni Samlan