I'm trying to get and print all emails from server using imaplib in Python, but it didn't print anything. I have gone through I want to grab all emails from an inbox using the Python IMAPLIB module... how can I do this? and the imaplib documentation. But the code didn't print the mails.
mail = imaplib.IMAP4_SSL(imap_host)
## login
mail.login(imap_user, imap_pass)
status, messages = mail.select('INBOX')
print(status)
if status != "OK":
exit("Incorrect mail box")
print(messages)
typ, data = mail.search(None, 'ALL')
for num in data[0].split():
typ, data = mail.fetch(num, '(RFC822)')
print('Message %s\n%s\n' % (num, data[0][1]))
mail.close()
mail.logout()
Here, the print(status) prints 'OK' but print(messages) prints [b'0']. Several answers from stackoverflow i have analyzed. I'm stuck in this, any suggestions. I want to print all the emails in the particular mailid.