I have this code to extract email body, but the output show the message and some encrypted information. I need help to get only the message.
Last version i've try the lib imaplib, but i don´t have sucess because all message it´s encrypted, so i change to poplib.
As future updates i want to add Subject, date and sender
#!/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
Using
imaplib
, ifa
is the raw email string: