Reputation: 187
I'm trying to fetch inboxs/emails from my gmail by using python. However, the code im using doesnt reem to run? I'm following a tutorial and my output is different. I'm new to python.
import email
import imaplib
username = '****@gmail.com'
password = '****'
mail = imaplib.IMAP4_SSL("imap.gmail.com")
mail.login(username, password)
mail.select("inbox")
When I run it via visual studio, I get this error.
I turned on let secure apps access feature on my google account, turned on imap on my gmail settings. What am I doing wrong? I'm trying to fetch emails from gmail and view inboxes and such.
Any help?
Upvotes: 0
Views: 575
Reputation: 797
Can you try this? I added a print statement and trying to access the content.
import imaplib
username = '****@gmail.com'
password = '****'
mail = imaplib.IMAP4_SSL(IMAP)
mail.login(USERNAME, PASSWORD)
for i in mail.list()[1]:
l = i.decode().split(' "/" ')
print(l[0] + " = " + l[1]) #should print the mail content that you can use as needed
Upvotes: 1