0

I just woke up in the morning and suddenly get this error as above while it was working perfectly, simple code as below to print the email body contents.

imapObj = imapclient.IMAPClient('outlook.office365.com', ssl=True) # Access IMAP server

imapObj.login('EMAIL@XYZ.COM', 'PASSWORD') # Credintial logins

imapObj.select_folder('INBOX', readonly=False) 

UIDs = imapObj.search(['FROM' , 'EMAIL@XYZ.COM'])

for i in UIDs:

    data = imapObj.fetch(i, ['BODY[]']) 

    message = pyzmail.PyzMessage.factory(data[i][b'BODY[]'])
    
       
    print(message.text_part.get_payload().decode(message.text_part.charset))
Alani
  • 73
  • 6
  • 3
    It would seem that `message.text_part` is `None`. – 0x5453 Jul 30 '21 at 15:07
  • what does it make it change to None ? how would extract email body as before? – Alani Jul 30 '21 at 15:12
  • According to the [docs](http://www.magiksys.net/pyzmail/api/pyzmail.parse.PyzMessage-class.html): *"None if the mail has not text content."* Note that in their [example](http://www.magiksys.net/pyzmail/#parse-an-email) they explicitly check to make sure `text_part is not None`. – 0x5453 Jul 30 '21 at 15:20
  • thank you, I checked the plain text in the inbox shows none while in other folder is a plaintext with this output instead of none : MailPart<*text/plain charset=us-ascii len=206>. – Alani Jul 30 '21 at 16:00

0 Answers0