Python 3 - How to extract message from an email [pending]

0

I have this code to extract messages from an email, but the output shows the message and some encrypted information. I need help getting the message.

In another version of the code, I tried the imaplib library but I was unsuccessful because all the messages were encrypted so I now used poplib .

Then I want to get the Subject of the email, the date and who sent it.

#!/usr/bin/env python3
# -- coding: utf-8 --

import email
import poplib

login = input('Email: ')
password = input('Password: ')
pop_server = 'pop-mail.outlook.com'
pop_port = 995

mail_box = poplib.POP3_SSL(pop_server, pop_port)
mail_box.user(login)
mailbox.pass_(password)
numMessages = len(mail_box.list()[1])

if numMessages > 15:
    numMessages = 15
for i in range(15):
    (server_msg, body, octets) = mail_box.retr(i+1)
    for j in body:
        try:
            msg = email.message_from_string(j.decode("utf-8"))
            strtext = msg.get_payload()
            print(strtext)
        except:
            pass

Update with Output:

--001a11440afa60ba050555c38489

Este =C3=A9 o body do Email

--001a11440afa60ba050555c38489

<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"><d=
iv dir=3D"ltr">Este =C3=A9 o body do Email</div>

--001a11440afa60ba050555c38489--

--f403045dd7a8ee72410555c397d6

njsdkbafj

--f403045dd7a8ee72410555c397d6

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr">njsdkbafj</div>

--f403045dd7a8ee72410555c397d6--
    
asked by anonymous 03.08.2017 / 18:08

1 answer

-1

Try using Base64 might be a good solution to your problem.

    
04.08.2017 / 11:27