IMAP in Corporate Gmail - python

I am trying to download emails using imaplib with Python. I have tested the script using my own email account, but I am having trouble doing it for my corporate gmail (I don't know how the corporate gmail works, but I go to gmail.companyname.com to sign in). When I try running the script with imaplib.IMAP4_SSL("imap.gmail.companyname.com", 993), I get an error gaierror name or service not known. Does anybody know how to connect to a my company gmail with imaplib?

IMAP server is still imap.gmail.com -- try with that?

If you're a domain admin you can use my library with a OAuth2 Service Account. If you're an individual user, you might want to look at my code for the oAuth2WebServerFlow. This should allow you to use OAuth (and not a password) to access GMail's IMAP.
https://github.com/richieforeman/oauth2gmail

Related

Using Google Gmail API for Desktop Application

I have a desktop application which sends email from Gmail using SMTP.
Since Less secure Apps will not longer be supported, I am trying to use Google API with OAuth2. Is there any other way I can use to send email from Gmail accounts?
Also, if I use Google API with OAuth2 can we configure the client ID and client secret generated from Admin Gmail account and use the same for all the other users for authorization?
I am following this tutorial:
https://www.youtube.com/watch?v=44ERDGa9Dr4
Thanks in advance!
I have a desktop application which sends email from Gmail using SMTP. Since Less secure Apps will not longer be supported, I am trying to use Google API with OAuth2.
If you want to stick with smtp did you consider checking out Did you consider checking Xoauth2?
Have you tried using an app password im not sure if thats going away as well.
Can we configure the client ID and client secret generated from Admin Gmail account and use the same for all the other users for authorization?
If you have a google workspace domain, Then you could use a service account and set up domain wide delegation which would allow the service account to impersonate any user on your domain.
If these are standard google gmail email accounts then you will need to use oauth2 to request consent from each user.
verification
remember if you switch to Oauth2 you will need to have your app verified

Authentication Error when trying to access a gmail business account to read emails - using IMAP_4SSL

I am trying to access a gmail account so I can read emails and save PDFs attached to those emails. I wrote the code and it works fine when I tested it on my personal gmail account (something#gmail.com), but now that I am trying to do it for this new address (reporting#company.com, which is a gmail business account) my code isn’t working to even connect.
I get an error message saying
Error: b’[AUTHENTICATIONFAILED] Invalid Credentials (Failure)’
I know the login email and the password are both correct. I have already downloaded the credentials.json file from the Google API page.
My code is as below:
Mail = imaplib.IMAP4_SSL(“imap.gmail.com”)
Mail.login(“reporting#company.com”,’password’)
If you're still using a password in your code, then you need to get your users to enable Less Secure Apps, or if they're using 2-Step Verification, create an App Password.
However, a better approach would be to use OAuth instead of a password. If you've downloaded the credentials.json file from the Google Developers Console, you already did the first step. :) Google has a guide to use OAuth with IMAP in Python, as well as a code sample (see the TestImapAuthentication method there).
All I had to do was enable 2-step authentication on the google account.

Programatically Send Notification Email for an Office 365 Hosted Email Using REST or Python

I am starting work on a project that will involve sending an auto generated email to a user. I am (most likely) going to build the application using Python and Django and host it as an Azure web app. The outgoing email address (hello#example.com) is hosted on Office 365. After some digging it looks like the recommended method of sending emails is the 365 Outlook API. All the documentation shows how to authenticate using AAD for a user that is logging in. However, I need to access the same email address regardless of who is using the web app.
Is there a way to securely get access to an AAD token on the backed of the server without storing a password in plaintext? Preferably the it would be in Python or REST but if need be I can switch technologies.
You can create an app only following Client Credentials Grant flow, leveraging which you can authenticate and authorize for AAD in backend.
Here is a code sample on GitHub https://github.com/Azure-Samples/active-directory-python-graphapi-oauth2-0-access, which builds an app-only app leveraging AAD in Django.
Any further concern, please feel free to let me know.

Error logging into Gmail Via Python [Unauthorized Client]

I'm using a python library to log into Gmail. Pretty simple to get started with.
I'm trying to log into my account via this code.
import gmail
g = gmail.login(username, password)
and I receive this error
gmail.exceptions.AuthenticationError
Because google blocked the sign in attempt.
My question is that, is there a way to better authenticate to gmail so Google doesnt block my requests to sign in? I rather not go through the process of generating an OAuth code only because I have multiple gmail accounts I want to log into and retrieve emails from.
Thanks!

Google Apps Engine mail fetch

How can I fetch mails from gmail account in Google Apps Engine Django application?
Configure your app to receive email, then, if it really has to be a gmail address, set up the gmail address to forward everything to your appspot address.
You could cronjob rss feed to gmail messages?
gmail rss
python cron
I would use libgmail -- seems to be the most popular pure-Python way to do it. However for app engine use I believe it would have to be ported to use urlfetch and I don't think anybody's done that yet (I'd happily receive news to the contrary!-).
Just use the Python's standard POP or IMAP client. Google does not provide a GMail API.

Categories

Resources