理解Python模块imaplib

  • imaplib

    1. Python Documents
    2. PyMOTW
    3. imaplib - IMAP4 协议 client 中文文档

    This module defines three classes:IMAP4(base class), IMAP4_SSL, IMAP4_stream, which encapsulate a connection to an IMAP4 server and implement a large subset of the IMAP4rev1 client protocol as defined in RFC 2060. It is backward compatible with IMAP4(RFC 1730) servers, but note that the STATUS command is not supported in IMAP4.

    上面提到的几个概念,参见《理解概念IMAP4、IMAP4rev1 client protocol》

  • IMAP4_SSL

    class imaplib.IMAP4_SSL(host='', port=IMAP4_SSL_PORT, keyfile=None, certfile=None, ssl_context=None)

    host默认localhost;

    port默认993;

  • 常用方法

    # IMAP类方法
    IMAP4 = IMAP(host, port) # 实例化imap客户端
    IMAP4.login(user, password)
    IMAP.list() # mailbox names list
    IMAP.select(mailbox= "INBOX", readonly= False) # 返回mailbox中的消息数量,一个tuple
    IMAP.search(charset, criterion[,...]) # 
    IMAP.fetch(message_set, message_parts)
    M.search(None, 'FROM', '"name"')
    M.search(None, '(FROM "name")')
    M.search('GB2312', 'SUBJECT "中文"'.encode('gb2312'))
    
  • Reference

  1. Python 接收附件
  2. python使用imap接收邮件的过程…郁闷的探索
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值