Accessing EMail Using IMAP In Python
Internet Message Access Protocol better known as IMAP is one of the most popular & widely used protocols for accessing emails from remote servers, the other one being POP (Post Office Protocol), and almost all modern email clients support both these protocols.
IMAP works on TCP/IP stack, and the server generally runs on port 143 and IMAPS (IMAP over SSL) on 993. IMAP is much more advanced than POP, you can use IMAP to fetch messages in part or full, create folder/sub-folders, move & copy messages from/to folders, upload new messages to the server, search for messages using various parameters, and more. The current version of IMAP is IMAP4 (version 4 revision 1).
In this article, we'll be looking into a few basic IMAP operations with some demo code.
The built-in Python module imaplib, the module makes it pretty simple to connect to IMAP & IMAPS severs, follow the sample code below:
Now, let's look at some more operations like list the folders and sub-folders, creating new folder/sub-folder, searching for messages, please follow the demo code, bit you have to try running it, tweaking it to get to understand it better.
|All times are GMT +5.5. The time now is 09:45.|