Python reads my Outlook email inbox and parses messages

Possible duplicate:
Reading emails from Outlook using Python via MAPI

I am completely new to Python and I was given the task of writing a program that connects to my Microsoft Outlook mailbox, goes through all emails, and if the subject has a certain word, then the details of the time and subject of the email will be stored in variables, and also the body of the email message has been processed, and the relevant information will be stored in variables. This information will then be stored in an external server / database. He should also be able to track any new emails that arrive in my inbox, and repeat the exercise of checking the subject line and take appropriate action.

I wrote the exact same program in C # before using the Interop library, but now it needs to be done in Python. I can figure out the detailed details by reading the module documentation later, but from a high point of view, which modules should I use. I do my research, and some of the modules that were mentioned include email, procmail, and imaplib, but what do Python veterans say for such a project that I overtake?

Thanks in advance for any help you could provide!

+8
python outlook mapi win32com imaplib
source share
1 answer

In one company I worked with, we have a mailbox for offers with websites that have “adult” material and one spam mailbox that should be blocked. As soon as I started working, I was “charged” with this “gracious” work. Checking this, there was something like 2,000 unread emails to block and 4,000 spam emails to block. Of course, this is a feature that needs to be automated, and I was looking for a good solution for me. What I've done:

[1] Using python IMAP to connect to the Exchange server [2] Using beatifulsoup (python) to analyze href values ​​inside an email [3] After that send an email with thanks for its cooperation (very important)

Three days after my boss thanked me for my great efforts, I answered all emails and we received compliments. Because NOW we are responsible for customers. (not me script)

Ok now let's make a plan

  • Check the imap module python [1] and then take one tutorial using ssl imap4 [4]
  • Decide which is best for YOUR problem? Download emails (pop3) or search and browse it on the server (IMAP).
  • CHECK if you can connect using IMAP4 or POP3 protocols. Before, the exchange will be an error in this part, please also check this error report [3]
  • Well, you are sure that you can connect using IMAP4 or POP3, now you will receive one message and analyze it using a beautiful soup or lxml. (in my case, I was looking for href and 'mailto:')
  • Make a good message using the 'from:' field, by email, by making it personal.
  • 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 provide google urls because of my low score.

I hope this answer gives you some good recommendations for your solution. Of course, you can make it more hax0r using lxml by sending data to the database. But after you connect and start to manipulate, you can do anything :)

+9
source share

All Articles