imaplib.IMAP4()
imaplib.IMAP4() is a Python function in the Imaplib Module category. Creates an IMAP4 client for reading/managing emails on a server. The syntax is imaplib.IMAP4(host="", port=143). Returns: IMAP4 object. A typical example: import imaplib
imap = imaplib.IMAP4("imap.gmail.com", 993)
imap.login("user@gmail.com", "password")
imap.select("INBOX")
type, data = imap.search(None, "ALL")
for num in data[0].split():
type, msg = imap.fetch(num, "(RFC822)")
print(msg[0][1])
imap.logout(). A close sibling is IMAP4.login(), which logs into the IMAP server with username and password. A close sibling is IMAP4.select(), which selects a mailbox for operation. A close sibling is IMAP4.search(), which searches for messages matching criteria. A close sibling is IMAP4.fetch(), which fetches message data (RFC822 full message, or headers/body parts). More about this category: IMAP4 email client — IMAP4, login, list, select, search, fetch, store. Related Imaplib Module entries: IMAP4.login(), IMAP4.select(), IMAP4.search(), IMAP4.fetch(), IMAP4.store(), IMAP4.list(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.