Get content from email

Asked

Viewed 26 times

0

I’m using the following:

import imaplib
import email

m = imaplib.IMAP4_SSL("imap.gmail.com", 993)
m.login("myemail","mypass")
m.select("Inbox")

result, data = m.uid('search', None, "ALL") # search all email and return uids
if result == 'OK':
    for num in data[0].split():
        result, data = m.uid('fetch', num, '(RFC822)')
        if result == 'OK':
            email_message = email.message_from_string(data[0][1])    # raw email text including headers
            print 'From:' + email_message['subject'] 

m.close()
m.logout()

I can only get the Subject from the email, and I want the content of the message. What are the values beyond Subject and from?

Using python 2.7

1 answer

0

Hello!

I believe this post can help you in this issue friend:

Utilization of imaplib (English) As a suggestion I leave the library Imapclient that I find much simpler to work with. Description of them:

Easy-to-use, Pythonic and complete IMAP client library.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.