read emails from gmail accountsas well as python module for using the standard smtp and imap email protocols warning highly recommend you set up separate email account for any scripts that send or receive emails this will prevent bugs in your programs from affecting your personal email account (by deleting emails or accidentally spamming your contactsfor exampleit' good idea to first do dry run by commenting out the code that actually sends or deletes emails and replacing it with temporary print(call this way you can test your program before running it for real sending and receiving email with the gmail api gmail owns close to third of the email client market shareand most likely you have at least one gmail email address because of additional security and anti-spam measuresit is easier to control gmail account through the ezgmail module than through smtplib and imapclientdiscussed later in this ezgmail is module wrote that works on top of the official gmail api and provides functions that make it easy to use gmail from python you can find full details on ezgmail at /ezgmailezgmail is not produced by or affiliated with googlefind the official gmail api documentation at / /referenceto install ezgmailrun pip install --user --upgrade ezgmail on windows (or use pip on macos and linuxthe --upgrade option will ensure that you install the latest version of the packagewhich is necessary for interacting with constantly changing online service like the gmail api enabling the gmail api before you write codeyou must first sign up for gmail email account at /quickstart/python/click the enable the gmail api button on that pageand fill out the form that appears after you've filled out the formthe page will present link to the credentials json filewhich you'll need to download and place in the same folder as your py file the credentials json file contains the client id and client secret informationwhich you should treat the same as your gmail password and not share with anyone else thenin the interactive shellenter the following codeimport ezgmailos os chdir( ' :\path\to\credentials_json_file'ezgmail init(make sure you set your current working directory to the same folder that credentials json is in and that you're connected to the internet the ezgmail init(function will open your browser to google sign-in page