Writing 'intercepted' e-mail message to a mailbox
Steve Purcell
stephen_purcell at yahoo.com
Thu Apr 19 04:42:37 EDT 2001
Jacobus van der Merwe wrote:
> I am redirecting all email sent user1 at myhost.co.za to a python script,
> which extracts certain data from the e-mail and writes it to file.
> But now I still want user1 to receive this e-mail.
>
> I read the incoming mail using
> mailMessage = rfc822.Message(sys.stdin)
>
> How can I get the message from my variable mailMessage into user1's
> mailbox?? I can not find a method that does it.
I presume you're on UNIX using the '.forward' mechanism.
Don't rely on your program to save the message to the user's mailbox. There
are all kinds of file locking issues.
Forward your mail instead to the 'procmail' program (http://www.procmail.org/).
Then your ~/.forward file would look like:
|/usr/bin/procmail
and your ~/.procmailrc would look something like:
PATH=/opt/bin:/usr/local/bin:/usr/bin:/bin
:0 c
| yourprogram.py
Procmail will then pipe the mail through your program *and* deliver to the
usual mailbox file as usual.
As an added bonus, you can add anti-spam rules to your .procmailrc like:
:0:
* ^FROM.*zzn.com
/dev/null
or even
:0:
* ^Subject:.*perl
/dev/null
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo
More information about the Python-list
mailing list