1

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.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144
  • Possible duplicate of [Python IMAPLIB HTML body parsing](https://stackoverflow.com/questions/52522113/python-imaplib-html-body-parsing) – stovfl Oct 03 '18 at 12:47
  • 1
    That seems to indicate there are zero messages in the inbox. – Max Oct 04 '18 at 03:07

0 Answers0