How to check mail from Amazon WorkMail in Python

Finally, Amazon added IMAP support to WorkMail, so now it’s pretty easy to get mail from it. Next is pretty simple piece of code how to get mail in Python3 from Amazon WorkMail: Python import sys import imaplib import email import email.header import datetime // find imap host for your region here: http://docs.aws.amazon.com/general/latest/gr/rande.html#wm_region M = imaplib.IMAP4_SSL('imap.mail.eu-west-1.awsapps.com') M.login('email@example.com', 'password') M.select("inbox") rv, data = M.search(None, "ALL") if rv != 'OK': print("No messages found!") else: for num in data[0].split(): rv, data = M.fetch(num, '(RFC822)') if rv != 'OK': print("ERROR getting message", num) continue msg = email.message_from_bytes(data[0][1]) hdr = email.header.make_header(email.header.decode_header(msg['Subject'])) subject = str(hdr) print('Message %s: %s' % (num, subject)) print('Date:', msg['Date']) 1234567891011121314151617181920212223242526272829 import sysimport imaplibimport emailimport email.headerimport datetime // find imap host for your region here: http://docs.aws.amazon.com/general/latest/gr/rande.html#wm_regionM = imaplib.IMAP4_SSL('imap.mail.eu-west-1.awsapps.com')M.login('email@example.com', 'password') M.select("inbox") rv, data = M.search(None, "ALL") if rv != 'OK':print("No messages found!")else:for num in data[0].split():rv, data = M.fetch(num, '(RFC822)')if rv != 'OK':print("ERROR getting message", num)continue msg = email.message_from_bytes(data[0][1])hdr = email.header.make_header(email.header.decode_header(msg['Subject']))subject = str(hdr) print('Message %s: %s' % (num, subject))print('Date:', msg['Date']) Here is pretty good imaplib...