Python read my outlook email mailbox and parse messages [duplicate]

徘徊边缘 提交于 2019-11-30 00:48:37
Carlos Henrique Cano

At one company I worked we have a mailbox for suggestion with websites that had 'adult' material and one mailbox for spam mail that should be blocked. Once I began working I was in 'charge' of this 'gracious' jobs. Checking it there was something like 2000 unread mails to block and 4000 spam mails to block too. Of course that is a function to be automatized and I looked for a good solution for me. What I did:

[1] Used python IMAP to connect to Exchange server [2] Used beatifulsoup (python) to parse the href values inside the email [3] After that send a email 'thanking' the user for its collaboration (very important)

Three days after my boss thanked me for the great effort I was doing answering all the e-mails and that we got compliments. Because NOW we are answering back the customers. (not me the script)

Ok. now lets do a plan

  1. Check the imap python module [1], and after take one tutorial using ssl imap4 [4]
  2. Decide What is best for YOUR problem? Download the emails (pop3) or search and browse it at server (IMAP).
  3. CHECK if you can connect using the protocols IMAP4 or POP3 Before, exchange is buggy in this part please check this bug report too [3]
  4. Ok, you are sure you can connect using IMAP4 or POP3, now fetch one message and parse it with beatiful soup or lxml. (my case I looked for href and 'mailto:')
  5. Do a nice message using the field 'from:' the email making it personal
  6. PROFIT

[1] google it imap python

[2] google it BeautifulSoup python

[3] http://support.microsoft.com/kb/296387

[4] http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/

Sorry but I had to give the google urls because of my low score.

I hope this answer give you some good pointers to your solution. Of course you can make it more hax0r using lxml, sending the data to a DB. But after you connect and start manipulating you can do anything :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!