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_emailvariable incommon.pyto your gmail address. - To send emails, use the
send_emails.pyscript:Output:python send_emails.py --helpFor 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 attachmentspython 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.pyscript. 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 --helpMarking 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 unreadMarking emails sent from [email protected] as Unread:python mark_emails.py "Google Alerts" --readpython mark_emails.py "[email protected]" -u - To delete emails, consider using
delete_emails.pyscript, e.g: for deleting emails about Bitcoin:python delete_emails.py "bitcoin" - If you want the full code, consider using
tutorial.ipynbfile. - Or if you want a all-in-one script,
gmail_api.pyis here as well!