POP and IMAP - Post Office Protocol and Internet Message Access Protocol
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的更多相关文章
- Internet Message Access Protocol --- IMAP协议
https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol Internet Message Access Protocol
- IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol)。
IMAP(Internet Mail Access Protocol,Internet邮件访问协议)以前称作交互邮件访问协议(Interactive Mail Access Protocol).IMA ...
- 开启网易邮箱客户端授权码-POP/SMTP/IMAP
打开网易邮箱首页 https://mail.163.com/ 登录邮箱. 点击上方设置,选择POP/SMTP/IMAP选项. 选择开启对应的协议,IMAP或者POP3分别为不同的收信协议 在新弹出的弹 ...
- LADP(Lightweight Directory Access Protocol)轻量目录访问协议~小知识
What is LDAP and how does it work(implementation)? LDAP stands for “Lightweight Directory Access Pro ...
- 服务信息块协议 SMB(Server Message Block protocol)
SMB(Server Message Block)是协议名,它能被用于Web连接和客户端与服务器之间的信息沟通. SMB协议 SMB最初是IBM的贝瑞·费根鲍姆(Barry Feigenbaum)研制 ...
- Advanced Message Queuing Protocol ( 1 ) 概述
The Advanced Message Queuing Protocol (AMQP)是一个标准开放的应用层的消息中间件(Message Oriented Middleware)协议.AMQP定义了 ...
- mail客户端POP和IMAP协议
POP-邮局协议 mail客户端如果使用POP协议,那么线上服务器的邮件将会自动下载到客户端. IMAP-因特网消息访问协议 mail客户端如果使用IMAP协议,邮件服务器上的邮件将不会自动下载到客户 ...
- IRC(Internet Relay Chat Protocol) Protocal Learning && IRC Bot
catalogue . Abstract . INTRODUCTION . 通信协议Connection Registration Action . 通信协议Channel operations Ac ...
- 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 ...
随机推荐
- 一次asp.net core3.1打造webapi开发框架的实践
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAigAAAAbCAYAAABWfHSvAAAH30lEQVR4nO1dy5GsMAx80RIESRAEST ...
- 图解kubernetes服务打散算法的实现源码
在分布式调度中为了保证服务的高可用和容灾需求,通常都会讲服务在多个区域.机架.节点上平均分布,从而避免单点故障引起的服务不可用,在k8s中自然也实现了该算法即SelectorSpread, 本文就来学 ...
- 《C# 爬虫 破境之道》:概述
第一节:写作本书的目的 关于笔者 张晓亭(Mike Cheers),1982年出生,内蒙古辽阔的大草原是我的故乡. 没有高学历,没有侃侃而谈的高谈阔论,拥有的就是那一份对技术的执著,对自我价值的追求. ...
- Eclipse常用快捷键【转】
Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键.1. [ALT+/]此快捷键为用户编辑的好帮手,能为用户提供内容的 ...
- 解决 VS Code 中 golang.org 被墙导致的 Go 插件安装失败问题
微软官方开发的 Go for Visual Studio Code 插件为 Go 语言 提供了丰富的支持.在 VS Code 中首次打开 Go 工作区后,VS Code 会自动检测当前开发环境为 Go ...
- 关于爬虫的日常复习(11)—— 实战:flask+redis维护代理池(to be continue)
- Scrapy信号量
1.类 from scrapy import signals class MySingle(object): def __init__(self): pass @classmethod def fro ...
- (分块)GukiZ and GukiZiana CodeForces - 551E
题意: 给你一段序列,并且有两种操作 操作①:将序列中从l-r每个元素加上x 操作②:在序列中找到ai=aj=y,j-i的最大值,如果找不到则输出-1 思路: 直接分块暴力即可 对于区间加,普通标记加 ...
- NIO&AIO编程模型
NIO线程模型 什么是NIO线程模型? 上图是NIO的线程模型, 基于select实现, 这种线程模型的特点: 多条channel通过一个选择器和单挑线程绑定, 并且在这种编程模型中, Cha ...
- tensorboard网络结构
一.tensorboard网络结构 import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data ...