To use the scripts here:
- Create your credentials file in Google API dashboard and putting it in the current directory, follow this tutorial for detailed information.
pip3 install -r requirements.txt
- Change
our_email
variable incommon.py
to your gmail address. - To send emails, use the
send_emails.py
script:Output:python send_emails.py --help
For example, sending to [email protected]:usage: send_emails.py [-h] [-f FILES [FILES ...]] destination subject body Email Sender using Gmail API positional arguments: destination The destination email address subject The subject of the email body The body of the email optional arguments: -h, --help show this help message and exit -f FILES [FILES ...], --files FILES [FILES ...] email attachments
python send_emails.py [email protected] "This is a subject" "Body of the email" --files file1.pdf file2.txt file3.img
- To read emails, use the
read_emails.py
script. Downloading & parsing emails for Python related emails:This will output basic information on all matched emails and creates a folder for each email along with attachments and HTML version of the emails.python read_emails.py "python"
- To mark emails as read or unread, consider using
mark_emails.py
:Output:python mark_emails.py --help
Marking emails from Google Alerts as Read:usage: mark_emails.py [-h] [-r] [-u] query Marks a set of emails as read or unread positional arguments: query a search query that selects emails to mark optional arguments: -h, --help show this help message and exit -r, --read Whether to mark the message as read -u, --unread Whether to mark the message as unread
Marking emails sent from [email protected] as Unread:python mark_emails.py "Google Alerts" --read
python mark_emails.py "[email protected]" -u
- To delete emails, consider using
delete_emails.py
script, e.g: for deleting emails about Bitcoin:python delete_emails.py "bitcoin"
- If you want the full code, consider using
tutorial.ipynb
file. - Or if you want a all-in-one script,
gmail_api.py
is here as well!