rgladwell / imap-upload

Python script for uploading a local mbox file to IMAP4 server.
Other
130 stars 30 forks source link

Using OAuth2 for Gmail IMAP #26

Closed kvdesai closed 3 years ago

kvdesai commented 3 years ago

Great work!

I am trying to use this tool to upload my emails from Thunderbird (68.10) on Ubuntu 18.04 to Gmail (Google Worksapce). While setting up Thunderbird for Gmail (IMAP), I realized that Gmail nowadays only allows authentication via OAuth2. Because of this reason, when I try this script with --username and --password it fails with the following error: Connecting to imap.gmail.com:993. IMAP4 error: [AUTHENTICATIONFAILED] Invalid credentials (Failure) Is there a workaround?

rgladwell commented 3 years ago

That's interesting. I wonder if others will have similar problems. So you can't log in on Thunderbird either?

You can try an app-specific password:

https://support.google.com/accounts/answer/185833?hl=en

kvdesai commented 3 years ago

Thanks for the blazing fast reply!! I can login on Thunderbird, because it allows OAuth2. The first time I try to read message after logging in, it opens up the OAuth2 login screen where I need to type in the password. Then Thunderbird is able to pull in the messages.

kvdesai commented 3 years ago

App-specific password looks promising. It requires 2-step verification, but I think I can set that up. Will definitely try that.

rgladwell commented 3 years ago

Please let me know if the app passwords work.

Gmail nowadays only allows authentication via OAuth2

Can you clarify if this is a new thing? Did the script work for you before this change?

kvdesai commented 3 years ago

App-specific passwords worked for me perfectly. I was able to upoload to Gmail and Timestamps and attachments are all preserved! This workaround may not work for Google Workspace users if for their org, the 2-step verification is not enabled by the Admin.

I am using this script for the first time. As others were able to use it without OAuth2, I assumed it was anew thing :-)

rgladwell commented 3 years ago

Glad we could get that fixed for you. Closing as there doesn't seem like there is any further action required on this.