- 论坛徽章:
- 15
|
Python处理电子邮件, 你自己做些修改。- import poplib
- import string
- from email import parser
-
- host = 'pop.qq.com'
- username = 'your_qq@qq.com'
- password = 'your_password'
-
- pop_conn = poplib.POP3_SSL(host)
- pop_conn.user(username)
- pop_conn.pass_(password)
-
- #从服务器获取邮件列表:
- messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
-
- # Concat message pieces:
- messages = ["/n".join(mssg[1]) for mssg in messages]
-
- #解析邮件到email object:
- messages = [parser.Parser().parsestr(mssg) for mssg in messages]
- for message in messages:
- addrfrom = str(message.get('from'))
- try:
- addrfrom.index('info@kingsoft.com')
- start_addr = addrfrom.index('<')
- end_addr = addrfrom.index('>')
- print addrfrom[start_addr + 1 : end_addr] #如果邮件是来自金山则打印他的标题
- except ValueError:
- continue
- pop_conn.quit()
复制代码 |
|