S
S
Sigure2017-04-05 14:27:33
Python
Sigure, 2017-04-05 14:27:33

Get the body of a python email?

Essence: there is a code that pulls an unread letter from the box, There are 2 links in the letter.
Together with the letter I receive everything at once, but only the body is needed, how to implement it?

import imaplib
import email

mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('mail, pass')
mail.list()
mail.select() # connect to inbox.

typ, data = mail.search(None, '(FROM "krikynchik")')

f=open('data', 'w')
for num in data[0].split():
    typ, data = mail.fetch(num, '(RFC822)')
    f.write('Message %sn%sn' % (num, data[0][1]))

f.close()
mail.close()
mail.logout()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2017-04-05
@Zelxat

s/RFC822/BODY[TEXT]/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question