This project uses Gmail API to send, search, delete and mark emails as read or unread.
- Clone repo & cd into directory
git clone https://github.com/AMuriuki/gmail-api-python.git
-
Enable Gmail API
You'll need a token to connect to Gmail's API. First head over to Google API's dashboard to enable the API.
Use the search bar to search for
Gmail API
, click on it, then enable it. Create an OAuth 2.0 client ID, click onCreate Credentials
and chooseOAuth Client ID
.Select
Desktop App
as the Application type and proceed. Go ahead and download the json file with your client ID & Secret.Move the file to the root of your project directory, and rename it to
credentials.json
-
Create virtual env & activate it (Optional)
python3 -m venv venv
. venv/bin/activate
- Install required modules
pip install -r requirements.txt
- Edit
env.example
accordingly and rename to.env
email_address="youremail@gmail.com"
# add email recipients seperated by a comma
recipients="someemail@example.com, anotheremail@example.com"
- To send email:
python send_email.py "THIS IS THE SUBJECT" "And this is the body of this test email" --files attachment1.txt test.png