0

I found a code here and tried it out for myself however I keep getting an error that I dont know how to resolve. The error is this: TypeError: initial_value must be str or None, not bytes this is caused by msg = email.message_from_string(j)

My question is how do i resolve this error? If i need to change it into a string how do i go about doing this? I am still new to python.

complete code:

import poplib,email

pop3_host = 'pop.gmail.com'
pop3_user = 'my_email'
pop3_pass = 'my_password'

## connect to host using SSL
pop3_mail = poplib.POP3_SSL(pop3_host)

## print the response message from server
print (pop3_mail.getwelcome())

## send user
pop3_mail.user(pop3_user)

## send password
pop3_mail.pass_(pop3_pass)

## let's fetch mail
print ("\n\n===\nLatest Mail\n===\n\n")

numMessages = len(pop3_mail.list())

for i in str(numMessages):
    for j in pop3_mail.retr(i)[1]:

        msg = email.message_from_string(j)  # new statement
        print(msg.get_payload())
lu_laude
  • 91
  • 1
  • 9

0 Answers0