I'm trying to receive emails on python with poplib, when I run the code I keep getting the following output sequence item 0: expected str instance, bytes found
. Here is the whole code, if anyone knows a much simpler way of printing the receiving mail, I would appreciate if you could comment it. I would also like to be able to print only the emails of an determinate email. Thankyou.
import poplib
from email import parser
pop_conn = poplib.POP3_SSL('pop.gmail.com')
pop_conn.user('mail@gmail.com')
pop_conn.pass_('password')
messages = [pop_conn.retr(i) for i in range(1, len(pop_conn.list()[1]) + 1)]
# Concat message pieces:
messages = ["\n".join(mssg[1]) for mssg in messages]
#Parse message intom an email object:
messages = [parser.Parser().parsestr(mssg) for mssg in messages]
print(message.keys())
for message in messages:
print(message['subject'])
print(message.get_payload())
pop_conn.quit()