Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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(superuser@mydomain.com). I want to forward all my emails(all mails with to:superuser@mydomain.com) to my personal email id: superuser@gmail.com. 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)?

share|improve this question

closed as off-topic by Jason C, John Mee, EdChum, Soner Gönül, Paul Lo Mar 20 at 9:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on professional server- or networking-related infrastructure administration are off-topic for Stack Overflow unless they directly involve programming or programming tools. You may be able to get help on Server Fault." – Jason C, EdChum, Soner Gönül, Paul Lo
If this question can be reworded to fit the rules in the help center, please edit the question.

    
How did this six year old question resurface? –  John Mee Mar 20 at 4:34

2 Answers 2

up vote -1 down vote accepted

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

share|improve this answer
    
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? –  None-da Feb 3 '09 at 16:59
    
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? –  None-da Feb 3 '09 at 20:02

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,webmaster@my-site.com

then run:

newaliases

Then mail sent to "superuser" would go to "marc" and "webmaster@my-site.com" instead.

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

share|improve this answer
    
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 –  None-da Feb 3 '09 at 18:32
    
Right -- suppose you want to forward the emails coming in to steven@mydomain.com to joeblow@gmail.com. On the mail server for mydomain.com, you'd add "steven: joeblow@gmail.com" to /etc/aliases, then run newaliases. That's all there is to it. –  Yoni Samlan Feb 5 '09 at 19:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.