ssl = True
today = datetime.today()
cutoff = today - timedelta(days=5)
server = IMAPClient(HOST, use_uid=True, ssl=ssl)
server.login(USERNAME, PASSWORD)
select_info = server.select_folder('INBOX')
messages = server.search(['FROM "Alerts@foobank.com"', 'SINCE %s' % cutoff.
    strftime('%d-%b-%Y')])
response = server.fetch(messages, ['RFC822'])
for msgid, data in response.items():
    msg_string = data['RFC822']
msg = email.message_from_string(msg_string)
print('ID %d: From: %s Date: %s' % (msgid, msg['From'], msg['date']))
Загрузите определенное электронное письмо из Gmail с помощью Python