温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python如何实现的接收邮件功能

发布时间:2021-04-06 10:37:52 来源:亿速云 阅读:277 作者:小新 栏目:开发技术

这篇文章将为大家详细讲解有关python如何实现的接收邮件功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

一 简介

本代码实现从网易POP3服务器接收邮件

二 代码

import poplib import re 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.entryPort.insert(tkinter.END,'110')     self.entryPop.place(x=50,y=5)     self.entryPort.place(x=50,y=30)     self.entryUser.place(x=50,y=55)     self.entryPass.place(x=50,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.user(user)       pop.pass_(pw)       stat=pop.stat()       self.text.insert(tkinter.END,'Staus:%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')         str_lines=[]         for l in lines:           str_lines.append(l.decode(encoding = 'utf-8'))         self.text.insert(tkinter.END,"\n".join(filter(rx_headers.match,str_lines)))         self.text.insert(tkinter.END,'\n')         self.text.insert(tkinter.END,"-"*30+'\n')     except Exception as e:         self.text.insert(tkinter.END,'接收错误\n') root =tkinter.Tk() window=Window(root) root.mainloop()

三 运行结果

python如何实现的接收邮件功能

关于“python如何实现的接收邮件功能”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI