python实现的接收邮件功能示例【基于网易POP3服务器】

作者:cakincqm 时间:2022-08-24 20:34:41 

本文实例讲述了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实现的接收邮件功能示例【基于网易POP3服务器】

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/chengqiuming/article/details/78601177

标签:python,接收邮件
0
投稿

猜你喜欢

  • ASP模拟POST提交数据的方法

    2010-01-14 20:06:00
  • 详解Python if-elif-else知识点

    2022-02-23 16:06:23
  • 详解SQL Server数据库状态和文件状态

    2024-01-26 14:09:28
  • Python网络爬虫之获取网络数据

    2022-10-09 12:35:54
  • python多线程、网络编程、正则表达式详解

    2023-03-03 21:33:14
  • python中将字典形式的数据循环插入Excel

    2023-07-05 01:49:19
  • Python的这些库,你知道多少?

    2021-12-12 04:02:39
  • 新手入门Mysql--概念

    2024-01-27 17:00:18
  • 利用Golang解析json数据的方法示例

    2024-04-27 15:36:04
  • Python(PyS60)实现简单语音整点报时

    2023-07-06 03:05:23
  • Google谷歌的CSS前景图片合并技术

    2009-07-13 12:21:00
  • css闭合浮动元素

    2008-05-09 19:41:00
  • python 解决mysql where in 对列表(list,,array)问题

    2024-01-27 06:34:23
  • c#编写的高并发数据库控制访问代码

    2024-01-16 04:57:04
  • PhpStorm的使用教程(本地运行PHP+远程开发+快捷键)

    2024-05-03 15:13:22
  • 详解Django中间件的5种自定义方法

    2022-07-24 03:51:43
  • Python容器类型公共方法总结

    2022-06-24 23:58:06
  • Pycharm基本操作及调试代码

    2022-08-13 08:38:55
  • Python Selenium截图功能实现代码

    2021-10-11 09:14:19
  • 网页栅格系统研究(4):技术实现

    2008-11-06 11:44:00
  • asp之家 网络编程 m.aspxhome.com