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. Web测试中定位bug的方法

    在web测试过程中,经常会遇到页面中内容或数据显示错误,甚至不显示,第一反应就是BUG,没错,确实是BUG.进一步了解这个BUG的问题出在那里,是测试人员需要掌握的,可以简单的使用浏览器自带开发者工具 ...

  2. LeetCode 第27题--移除元素

    1. 题目 2.题目分析与思路 3.代码 1. 题目 给定 nums = [3,2,2,3], val = 3, 函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2. 你不需要考虑数组 ...

  3. 我终于学会了使用python操作postgresql

    一 前言 这篇文章不仅适合pgsql,更适合mysql,思路都是一致的,如果读者学会使用psycopg2操作pgsql,那么使用PyMySQL 操作mysql也是很简单:本篇文章涵盖内容广泛,提供的操 ...

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

    指定设置选项 设置页面使用户可以指定代理设置或安装附加组件. 用户在简介页面上点击"设置"来指定设置选项. 指定代理设置 默认情况下,安装程序使用系统代理设置.用户可以选择不使用或 ...

  5. vue需要知道哪些才能算作入门以及熟练

    前两天接到一个面试官问我vue什么程度才算作可以用于开发,以前从没遇到过类似问题.只能大致说了一些,事后觉得也应该总结一下,前端vue这么火热那究竟什么才算做入门什么才算做熟练,只是我个人观点,不代表 ...

  6. 4、python基础语法

    前言:本文主要介绍python的一些基础语法,包括标识符的定义.行和缩进.引号和注释.输入输出.变量的定义. 一.标识符 1.凡是我们自己取的名字,都是标识符. 2.在Python里,标识符由字母.下 ...

  7. 彻底理解Future模式

    先上一个场景:假如你突然想做饭,但是没有厨具,也没有食材.网上购买厨具比较方便,食材去超市买更放心. 实现分析:在快递员送厨具的期间,我们肯定不会闲着,可以去超市买食材.所以,在主线程里面另起一个子线 ...

  8. 正斜杠(" / ")和反斜杠(" \ ")的区别

    反斜杠“\”是电脑出现了之后为了表示程序设计里的特殊含义才发明的专用标点.所以除了程序设计领域外,任何地方都不应该使用反斜杠. 如何区分正反斜杠 英语:"/" 英文是forward ...

  9. python 抓一下 循环的访问也可以

    #!/usr/bin/python # -*- coding: utf-8 -*- #encoding=utf-8 #Filename:urllib2-header.py import urllib2 ...

  10. 异想家Eclipse的偏好配置

    1.汉化 http://www.eclipse.org/babel/downloads.php 找到Babel Language Pack Zips,下面选自己版本点进去,找到如下类似的中文包: Ba ...