POP and IMAP - Post Office Protocol and Internet Message Access Protocol

 用来从 SMTP Server 上下载邮件的协议.

     POP - The Post Office Protocol
通过 poplib 链接服务器,
例子,
import sys
import poplib, email
host = ''
userid = 'userid'
PW = 'PW'
storedir = '' # email stored directory(the mailbox)
P = poplib.POP3(host)
try:
P.user(userid)
P.pass_(PW)
except poplib.error_proto as e:
print("Login failed: ", e)
sys.exit() maillist = P.list()[1] # the list of message in the mailbox
print(" %d mails." % len(maillist))
dellist = [] for item in maillist: # email download
number, octets = item.split(' ')
print("Start downloading mail %s (%S Bytes)" % (number, octets))
lines = P.retr(number)[1] # retrieve the 'number'th email
msg = email.message_from_string("\n".join(lines)) # email object
with open(storedir) as FH:
FH.write(msg.as_string(unixfrom=1) + "\n")
dellist.append(number)
print("Downloaded mail %s (%S Bytes)" % (number, octets)) counter = 0
for num in dellist: # delete email
counter += 1
print("Deleting mail %d of %d" %(counter, len(dellist)))
P.dele(number) # delete mail print("%d emails were deleted from server" % counter)
P.quit() # logout from server IMAP - Internet Message Access Protocol
相比于 POP 协议 IMAP 更加完善,且功能更加强大
例子, opens a mailbox and retrieves and prints all messages: import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
print('Message %s\n%s\n' % (num, data[0][1]))
M.close()
M.logout() Reference,
python doc,
https://docs.python.org/3/library/imaplib.html

POP and IMAP - Post Office Protocol and Internet Message Access Protocol的更多相关文章

  1. Internet Message Access Protocol --- IMAP协议

    https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol   Internet Message Access Protocol

  2. IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol)。

    IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol).IMA ...

  3. 开启网易邮箱客户端授权码-POP/SMTP/IMAP

    打开网易邮箱首页 https://mail.163.com/ 登录邮箱. 点击上方设置,选择POP/SMTP/IMAP选项. 选择开启对应的协议,IMAP或者POP3分别为不同的收信协议 在新弹出的弹 ...

  4. LADP(Lightweight Directory Access Protocol)轻量目录访问协议~小知识

    What is LDAP and how does it work(implementation)? LDAP stands for “Lightweight Directory Access Pro ...

  5. 服务信息块协议 SMB(Server Message Block protocol)

    SMB(Server Message Block)是协议名,它能被用于Web连接和客户端与服务器之间的信息沟通. SMB协议 SMB最初是IBM的贝瑞·费根鲍姆(Barry Feigenbaum)研制 ...

  6. Advanced Message Queuing Protocol ( 1 ) 概述

    The Advanced Message Queuing Protocol (AMQP)是一个标准开放的应用层的消息中间件(Message Oriented Middleware)协议.AMQP定义了 ...

  7. mail客户端POP和IMAP协议

    POP-邮局协议 mail客户端如果使用POP协议,那么线上服务器的邮件将会自动下载到客户端. IMAP-因特网消息访问协议 mail客户端如果使用IMAP协议,邮件服务器上的邮件将不会自动下载到客户 ...

  8. IRC(Internet Relay Chat Protocol) Protocal Learning && IRC Bot

    catalogue . Abstract . INTRODUCTION . 通信协议Connection Registration Action . 通信协议Channel operations Ac ...

  9. OSA-MAC: A MAC Protocol for Opportunistic Spectrum Access in Cognitive Radio Networks

    This full text paper was peer reviewed at the direction of IEEE Communications Society subject matte ...

随机推荐

  1. 理解 SQL 开窗函数

    一次面试被问到开窗函数,懵逼了,赶紧补补总结一下.... 开窗函数也是函数,所以 比如在原来的查询上添加一个总数列 create table ztest( id int identity, c1 in ...

  2. 读取Core下的appsettings.json的值的时候中文乱码

    这个百度一下一大堆,我就用的这个:然后重新生成一次就好了. 2.有的是更改VS的什么高级保存之类的,我记得之气设置过, 然后就是:这篇文章

  3. Redux 一步到位

    简介 Redux 是 JavaScript 状态容器,提供可预测化的状态管理 Redux 除了和 React 一起用外,还支持其它库( jquery ... ) 它体小精悍(只有2kB,包括依赖) 由 ...

  4. Excel-条件格式

    今天运用了一下条件格式中的自建规则进行公式筛选, 设置格式那里一定要将$P$8修改为$P8 然后双击修改后的第一项进行单元格的自动填充

  5. 2020寒假学习01 Scala 编程初级实践

    1. 计算级数请用脚本的方式编程计算并输出下列级数的前 n 项之和 Sn,直到 Sn 刚好大于或等于 q为止,其中 q 为大于 0 的整数,其值通过键盘输入. Sn = 2/1+3/2+4/3+... ...

  6. Qt Installer Framework翻译(5-3)

    推广更新 创建在线安装程序,以便能够向安装产品的用户推广更新. 为了推广更新,需要执行以下步骤: 将待更新内容复制到package文件夹. 在package.xml文件中增加待更新组件的元素的值. 使 ...

  7. Redis系列-存储hash主要操作命令

    Redis系列-存储篇hash主要操作函数小结 hash是一些列key value(field value)的映射表.常常用其存储一些对象实例.相对于把一个对象的各个字段存储为string,存储为ha ...

  8. centos7的新特性

    1.修改主机名方式改变 centos6在/etc/ centos7使用命令hostnamectl set-hostname 主机名2.修改时间方式改变3.查看IP地址ifconfig不再支持改用ip4 ...

  9. RainbowPlan-Alpha版本发布2

    博客介绍 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ 这个作业要求在哪里 https:// ...

  10. GitHub 上这几个沙雕项目,够我玩几天

    在家里都憋坏了吧?每天睡了吃吃了睡,该找点事做做了,今天推荐几个好(沙)玩(雕)的开源项目,好在家打发时间. 91 吴先生 一个在线的 PornHub 风格 Logo 生成工具 Logoly.Pro ...