Conquer Your Inbox: Automate Gmail Tasks!

task-image

Conquer Your Inbox: Automate Gmail Tasks!

With so much email clutter these days it’s really difficult to find emails that requires me to take an ‘action’. Some actions include emails that remind me to pay my bills or taxes or anything else really important. As a software engineer I decided to take matters into my own hands. The first thing to do is to explore all the google services and see how this can be reliably automated. Ideally I would want some sort of notification to be sent to my phone when some email reaches my inbox. Unfortunately due to sheer amount of emails, i often dismiss many emails without reading them carefully, or i might miss notifications sent on certain days. After exploring some google services, i decided that the best way was to create a google task from emails that i receive everyday. This google task will send a notification to my phone to take action at 9am the next day.

Solutioning

I needed a way to specify what is important. After some thought I figured that google sheets was the best way to develop the solution. I would have 1 column specifying the name and another column specifying what i was searching for. Google app script seems like the perfect use case for this. Google apps script is very generous, providing 90 minutes of execution time per day, and 6 minutes per execution, more than enough for scanning emails.

Specify email matching criteria

Firstly, I create a google sheet and then specify what is important to me.

Alt text

Google app script

Seondly, my google app script scans this sheet and then scans my emails on a daily basis. If it matches the criteria it will create a google tasks that will be sent to my phone for me to complete it. At first I tried using regexes to match my email subjects but it’s really hard to input regexes into google sheets and read the regex from the google sheets. After some exploration, I decided to use the ‘query’ feature in Gmail (the query feature is an advanced search feature in gmail that searches your inbox based on the search feature in gmail), this is also what i specify in column B in the google sheet above.

Advanced Search with Gmail,query is in the search box
Advanced Search with Gmail,query is in the search box

To create the script, just click the extensions tab in google sheets and click google app script. In the services tab on the left add Gmail and Tasks. This is to allow the script to access your gmail and your tasks. The sample script is seen below.

Cron Scheduling

Finally on the left hand panel in google app script, click triggers and let it run on a daily basis from 12am -1am. A task will be created automatically and i will be notified on my phone at 9am the next day to complete my task.

Add trigger for the script and run the main function
Add trigger for the script and run the main function

Conclusion

Honestly, I am surprised that google allows consumers to run scripts for free. The cost for google is probably very low, as it likely uses google cloud functions ‘spot computing’ (as it does not run on a fixed time but rather anytime within the hour specified). Also it’s incredibly reliable for a free service as i have not encountered any bugs so far and it has ran flawlessly everyday without fail. As for the convenience that it brings for me? Hopefully i will not miss any credit card or tax payments that are sent to my email in the future!

p.s. blog title is generated by ChatGPT for clicks. Everything else, including code is written by me, though i have used chatgpt’s assistance for writing a very very small portion of the scripts.