【脚本语言系列】关于Python邮件服务poplib,你需要知道的事
2017-05-11 09:39
996 查看
如何使用poplib
使用poplib接收QQ邮件注意:使用第三方邮件客户端,需要使用短信开通并获取授权码。
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
# -*- coding:utf-8 -*- # import re import poplib import Tkinter class Window: def __init__(self, root): label1 = Tkinter.Label(root, text = 'POP3') label2 = Tkinter.Label(root, text = 'Port') label3 = Tkinter.Label(root, text = '用户名') label4 = Tkinter.Label(root, text = '密码') label1.place(x = 5, y = 5) label2.place(x = 5, y = 30) label3.place(x = 5, y = 55) label4.place(x = 5, y = 80) self.entryPOP = Tkinter.Entry(root) self.entryPort = Tkinter.Entry(root) self.entryUser = Tkinter.Entry(root) self.entryPass = Tkinter.Entry(root, show='*') self.entryPOP.insert(Tkinter.END, "pop.qq.com") self.entryPort.insert(Tkinter.END, "995") self.entryUser.insert(Tkinter.END, "********@qq.com")# ******@qq.com为测试邮箱,下同 self.entryPass = Tkinter.Entry(root, show='*') self.entryPass.insert(Tkinter.END, "****************") # 填入“授权码” self.entryPOP.place(x = 40, y = 5) self.entryPort.place(x = 40, y = 30) self.entryUser.place(x = 40, y = 55) self.entryPass.place(x = 40, y = 80) self.get=Tkinter.Button(root, text = '收取邮件', command = self.Get) self.get.place(x=60, y=120) self.text = Tkinter.Text(root) self.text.place(y=150) def Get(self): try: host = self.entryPOP.get() port = int(self.entryPort.get()) user = self.entryUser.get() pw = self.entryPass.get() # pop = poplib.POP3(host) pop = poplib.POP3_SSL(host, port) pop.set_debuglevel(1) pop.user(user) pop.pass_(pw) stat = pop.stat() self.text.insert(Tkinter.END,'Status: %d message(s), %d bytes\n' % stat) rx_headers = re.compile(r"^(From|To|Subject)") for n in range(stat[0]): response, lines, bytes = pop.top(n+1, 10) self.text.insert(Tkinter.END,"Message %d (%d bytes)\n" % (n+1, bytes)) self.text.insert(Tkinter.END, "-" * 30 + '\n') self.text.insert(Tkinter.END, "\n".join(filter(rx_headers.match, lines))) self.text.insert(Tkinter.END, "\n") self.text.insert(Tkinter.END, "-" * 30 + "\n") except: self.text.insert(Tkinter.END, '接收错误\n') root = Tkinter.Tk() window = Window(root) root.minsize(600, 480) root.mainloop()
1. 客户端界面
2. 交互信息
3. 收信信息
什么是poplib
Python中poplib模块提供了对POP3协议的支持。使用POP3协议可以登录E-mail收取邮件。
相关文章推荐
- 【脚本语言系列】关于Python邮件服务smtplib,你需要知道的事
- 【脚本语言系列】关于Python网页服务Apache,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化webbrowser模块,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化REST,你需要知道的事
- 【脚本语言系列】关于Python网页服务Microsoft IIS,你需要知道的事
- 【脚本语言系列】关于Python网页服务Plone,你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化Web API,你需要知道的事
- 【脚本语言系列】关于Python网页服务Zope, 你需要知道的事
- 【脚本语言系列】关于PythonWeb服务自动化BeautifulSoup,你需要知道的事
- 【脚本语言系列】关于Python图像处理scikits-image, 需要知道的事
- 【脚本语言系列】关于Python数据库处理MySQL, 你需要知道的事
- 【脚本语言系列】关于PythonWeb访问urllib,你需要知道的事
- 【脚本语言系列】关于Python性能分析工具timeit, 你需要知道的事
- 【脚本语言系列】关于Python数值计算Pandas,你需要知道的事
- 【脚本语言系列】关于Python测试工具Pyflakes, 你需要知道的事
- 【脚本语言系列】关于PythonGUI编程wxPython, 你需要知道的事
- 【脚本语言系列】关于Python机器学习scikits-learn,你需要知道的事
- 【脚本语言系列】关于Python开发环境搭建,你需要知道的事
- 【脚本语言系列】关于Python代码分析工具line_profiler,你需要知道的事
- 【脚本语言系列】关于Python调试报错,你需要知道的事