2010-05-01

Downloading your e-mail on a server to process

You know all the great features of craigslist and Facebook, that use anonymous, standalone e-mail for forwarding request to an ad owner or replying to a message via e-mail.

Well, I will show you how to do something like these.

Scenario: An chronological script will download new e-mails, then a Python script will process on these e-mails.

For downloading e-mails, I used getmail4. The best tutorial for it can be found here.

For my case, /home/manchurian/.getmail/getmailrc looks like this:

[retriever]
type = SimplePOP3Retriever
server = [my_mail_server]
username = [my_mail]
password = [my_mail_password]

[destination]
type = Mboxrd
path = /home/manchurian/inbox

Make the mail downloading automatic using crontab -e:

* * * * * getmail -n
-n is for retrieving new mails only.

Now it is time to process the downloaded mails anyway you want:

import mailbox
mails = mailbox.mbox("/home/manchurian/inbox")

mails.lock()

try:
   for m in mailbox:
      if m['from'] == 'abc@abc.org':
         print m['subject']
finally:
   mails.unlock()

Cheers,

5 comments:

  1. blogoor ni zochilloo,ene mergejliig ezemshij bui humuust medeelel uguhuur blog bn gj bodloo, amjilt hu:)

    ReplyDelete
  2. Humuus Anonymous reply hiiheer haanahiin hen gedeg ni medegdehgui :(

    ReplyDelete
  3. hehe,Zulaa bnaa.Bi sain yavj irsen kk,ta nar bgagui bol ongotsnooso hotsroh bsan shu gj:)

    ReplyDelete
  4. aan ashgui dee neeree sandargasan shuu te hehe, avtobusand bsan humuus dooglood ineej bsanuu hehe.

    ReplyDelete
  5. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. youtube to mp3 converter

    ReplyDelete