Python读取我的Outlook电子邮件邮箱并解析消息 [英] Python read my outlook email mailbox and parse messages

查看:1841
本文介绍了Python读取我的Outlook电子邮件邮箱并解析消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
通过MAPI从带有Python的Outlook中读取电子邮件

我对Python完全陌生,并且被赋予编写连接到我的Microsoft Outlook邮箱,浏览所有电子邮件的程序的任务,并且如果主题有特定的单词,那么电子邮件时间和主题的详细信息将保存在变量中,以及将解析电子邮件正文并将相关信息存储在变量中.然后,此信息将存储在外部服务器/数据库中.它还需要能够监视进入我的邮箱的所有新电子邮件,并重复检查主题行并采取适当措施的操作.

我之前使用Interop库用C#编写了完全相同的程序,但是现在需要用Python来完成.我可以通过稍后阅读模块文档来弄清细节,但是从较高的角度来看,我应该使用哪些模块.我一直在进行研究,提到的一些模块包括电子邮件,procmail和imaplib,但是对于我正在从事的那种项目,这里的Python老手们有何建议?

在此先感谢您可能提供的帮助!

解决方案

在我工作的一家公司中,我们有一个建议邮箱,其中包含具有成人"材料的网站,还有一个邮箱用于应阻止的垃圾邮件. 开始工作后,我将负责这项丰盛的"工作. 检查是否有类似2000封未读邮件和4000封垃圾邮件的邮件. 当然,这是一个要自动化的功能,我为我寻找了一个好的解决方案. 我做了什么:

[1]使用python IMAP连接到Exchange服务器 [2]使用beatifulsoup(python)解析电子邮件中的href值 [3]之后,向用户发送一封感谢"用户的电子邮件(非常重要)

在老板感谢我三天的努力之后,我做了三天,我正在回答所有电子邮件,并得到了我们的称赞.因为现在我们正在回馈客户. (不是我的脚本)

好的.现在开始制定计划

  1. 检查imap python模块[1],然后使用ssl imap4 [4]上一本教程
  2. 决定最适合您的问题的是什么?下载电子邮件(pop3)或在服务器(IMAP)上进行搜索和浏览.
  3. 检查是否可以使用IMAP4或POP3协议进行连接.在此之前,交换存在错误,请也检查此错误报告[3]
  4. 好吧,您确定可以使用IMAP4或POP3进行连接,现在获取一条消息并用美丽的汤或lxml对其进行解析. (我的情况是我寻找的是href和'mailto:')
  5. 在发件人:"字段中使用个性化的电子邮件来做个好消息
  6. 利润

[1] google it imap python

[2]在Google上搜索BeautifulSoup python

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

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

对不起,但是由于我的得分太低,我不得不提供google网址.

我希望这个答案能为您提供一些解决方案的很好的指导. 当然,您可以使用lxml使其更具有hax0r的特性,然后将数据发送到DB. 但是,在连接并开始操作之后,您可以执行任何操作:)

Possible Duplicate:
Reading e-mails from Outlook with Python through MAPI

I am completely new to Python and have been given the task to write a program that connects to my Microsoft Outlook mailbox, goes through all the emails and if the subject has a certain word, then the details of the email time and subject will be saved in variables, as well as the email message body will be parsed and relevant information will be stored in variables. Then this information will be stored in an external server/database. It also needs to be able to monitor any new emails that comes to my mailbox and repeat the drill of checking the subject line and taking appropriate action.

I have written exactly the same kind of program in C# earlier using the Interop library, but now need to do this in Python. I can figure out the nitty-gritty details by readin gthe module documentations later on, but from a high level perspective what modules should I use. I have been doing my research and some modules that have been mentioned include email, procmail and imaplib, but what do the Python veterans here recommend for the kind of project I am overtaking?

Thanks in advance for any help you might be able to provide!

解决方案

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 :)

这篇关于Python读取我的Outlook电子邮件邮箱并解析消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆