This is a little project inspired by a personal need. It downloads all emails to or from an address in your gmail account.
- Clone this repository
- Navigate to the 'gmailfetcher' directory
- Create a virtual environment:
python -m venv venv
(Windows/Linux) orpython3 -m venv venv
(Mac) - Activate the virtual environment
.\venv\Scripts\activate
(Windows) orsource venv/bin/activate
(Mac/Linux) - Install the necessary packages:
pip install -r requirements.txt
(Note: you can also install pip-tools then runpip-compile
to generate a new requirements.txt)
- Go the the Google Cloud Console and create an account if you don't have one
- Using the navigation menu in the top-left of the screen, go to
APIs & Services
, thenEnable APIs and Services
- Search
gmail
in the box and find the Gmail API, then enable it - In the
APIs & Services
menu, clickCredentials
, then clickCreate Credentials
, thenOAuth Client ID
- Follow the prompts to generate credentials
- Once you've created the credentials, you should see them on the main credentials page. Download the credentials JSON and save it to the gmailfetcher folder
- The first time you run the program you will need to authorize the app via your browser
- Set the EMAIL_ADDRESS variable in retrieve_emails.py to the address whose emails you want to get.
- Run the program:
python retrieve_emails.py
- If everything was set up correctly, the raw emails will be saved to the raw_emails directory, and the cleaned emails will be saved to the cleaned_mails directory!