This script facilitates the automation of fetching emails from a user's Gmail account and storing them into a MongoDB Atlas Cloud database. The emails fetched are filtered by specific labels such as Promotions, Social, Updates, and Forums. The script is intended to run continuously, checking for new emails every minute.
google-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
pymongo
schedule
You can install the necessary dependencies via pip:
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client pymongo schedule
- Create a project on the Google Cloud Platform Console.
- Enable the Gmail API for your project.
- Download the client configuration file
credentials.json
and place it in the root directory of this script. - Setup a MongoDB Atlas cluster and obtain the connection string.
- Set up your Gmail API credentials and save them as
credentials.json
in the script directory. - Update the MongoDB connection string in the
MongoClient
instantiation within thesend_emails_to_mongodb
function.
Run the script from the command line:
python gmail.py