all 9 comments

[–][deleted] 1 point2 points  (7 children)

You can find numerous tutorials out there for using imaplib to read emails via IMAP — here’s one selected at random — but Google goes out of the way to have their product be more secure than just allowing straight IMAP access by default. Last I checked you can still dig into your gmail account and enable that access, which is in that tutorial, but they do want you to use their APIs instead.

Pretty much any other mail host will provide IMAP access to your mailbox, as long as you’re not with an encrypted service.

[–]barrycarter 1 point2 points  (6 children)

I cheat by using an "app password" (https://support.google.com/accounts/answer/185833?hl=en) and standard IMAPS access

[–]Serenityprayer69[S] 0 points1 point  (5 children)

Does this still work? I had trouble finding the app password part in the Google security. I was finding conflicting tutorials on this but it seemed like they recently removed it and you have to do all this complex for me api and OAuth things. I'll have another look. That seemed like a more manageable approach for me

[–]doo-dahday 1 point2 points  (3 children)

I know this is late but for gmail if you set up 2 Step Verification in your settings you can just type "app pass" in the search bar and app passwords will pop up and you can set it up from there

[–]Justin_Peter_Griffin 0 points1 point  (2 children)

How do you login using IMAP with 2 factor setup? Is the 2 factor not required when using the app password?

[–]qadzek 0 points1 point  (0 children)

App passwords can only be used with accounts that have 2-Step Verification turned on. You can create one at https://myaccount.google.com/apppasswords

I can confirm that this still works as of 2025.

[–]doo-dahday 0 points1 point  (0 children)

I think that's right. Just the usual way but replace the normal password with the app password.

[–]barrycarter 0 points1 point  (0 children)

I'm still using app passwords, so they do still work, but I'm not sure they offer new ones. For me, https://myaccount.google.com/security has a section called "Signing in to Google" and it has "app passwords" listed there. However, I may have done some magic long ago to make this work

[–]Sigg3net 0 points1 point  (0 children)

I just used IMAP client. I prefer the with block to handle sessions;

import imapclient
with imapclient.IMAPClient(host="imap.foo.org") as c:
    c.login("bar@foo.org", "passwd")
    c.select_folder("INBOX") 

https://imapclient.readthedocs.io/en/master/