View difference between Paste ID: ZK2m9iTe and x3wB9gJ0
SHOW: | | - or go back to the newest paste.
1
import email
2
import imaplib
3
4
5
server = "imap.mail.ru"
6
port = "993"
7
login = "[email protected]"
8
password = "moms_lover"
9
imaplib.Debug = 4
10
get_mail = imaplib.IMAP4_SSL(server, port)
11
get_mail.login(login, password)
12
get_mail.select('INBOX', readonly=True)
13
typ, data = get_mail.search(None, 'UNSEEN')
14
for i in data[0].split():
15
    typ, data = get_mail.fetch(i, '(RFC822)')
16
    print(data[0][1])
17-
    msg = email.message_from_bytes(data[0][1])
17+
    msg_string = data[0][1].decode('utf-8')
18-
    print(msg.get_payload(0))
18+
    msg = email.message_from_string(msg_string)
19
    for part in msg.walk():
20
        if part.get_content_type() == "text/plain":
21
            txt_msg = part.get_payload()
22
            print(txt_msg)
23
        else:
24
            continue
25
get_mail.close()
26
get_mail.logout()