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

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

问题描述

<块引用>

可能的重复:
使用 Python 通过 MAPI 从 Outlook 读取电子邮件

我是 Python 的新手,我的任务是编写一个程序,该程序连接到我的 Microsoft Outlook 邮箱,浏览所有电子邮件,如果主题有某个词,那么电子邮件时间和主题的详细信息将保存在变量中,电子邮件正文将被解析,相关信息将存储在变量中.然后此信息将存储在外部服务器/数据库中.它还需要能够监控进入我邮箱的任何新电子邮件,并重复检查主题行并采取适当措施的练习.

我之前使用 Interop 库在 C# 中编写了完全相同类型的程序,但现在需要在 Python 中执行此操作.我可以通过稍后阅读模块文档来弄清楚细节,但从高层次的角度来看,我应该使用哪些模块.我一直在做我的研究,提到的一些模块包括 email、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 进行连接,现在获取一条消息并使用 beatiful soup 或 lxml 对其进行解析.(我的情况是我查找了 href 和mailto:")
  5. 使用发件人:"字段写一个好消息,使其个性化
  6. 利润

[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/

抱歉,由于我的分数很低,我不得不提供谷歌网址.

我希望这个答案能为您的解决方案提供一些好的指导.当然,您可以使用 lxml 使其更加 hax0r,将数据发送到数据库.但是在您连接并开始操作后,您可以做任何事情:)

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天全站免登陆