Search code examples
pythonimapclient

Get content of a mail IMAPCLIENT


I am using the IMAPclient to get the content of emails, so i made this piece of code :

messages = server.search(['FROM', user['email']], charset='UTF-8')
if len(messages) > 0:
    for mail_id, data in server.fetch(messages, ['ENVELOPE']).items():
        envelope = data[b'ENVELOPE']

How can I have the content of the emails?


Solution

  • Don't know if you found the answer elsewhere... try:

       messages = server.search(['FROM', user['email']], charset='UTF-8')
       if len(messages) > 0:
           for mail_id, data in server.fetch(messages,['ENVELOPE','BODY[TEXT]']).items():
               envelope = data[b'ENVELOPE']
               body = data[b'BODY[TEXT]']
    

    The email content is in body.