理解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接收邮件的过程…郁闷的探索

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/106311085
今日推荐