Retrieving e-mail messages with
imaplib is also easy to achieve. In this recipe, we will learn how to do that with Python code. In this recipe, we will search for e-mails with a particular subject line and fetch the latest message from the inbox that matches a predefined criteria.
We continue to use the
imaplib module for reading e-mail messages, so no new installations are required for this recipe.
toaddressto log in to the server. Once we're logged in, we select the default inbox, fetch e-mail messages, and read them. Let's look at the complete code:
import config, imaplib M = imaplib.IMAP4_SSL("imap.gmail.com", ...