Forget Gmail filters, let Google sort your inbox using Machine Learning algorithms
Among the multitude of programming APIs provided by Google lies a jewel called Prediction API. It has a high-quality classifier that allows for continuous learning with model updates.
Let's quickly use it to automatically sort incoming mail into your existing labels. The most tedious part is configuration:
- Create a new Blank Project in Google Apps Script and enable Prediction API in the
Resources/Advanced Google services…menu.
- Sign up for the Google Developers Console and take the 300$ free credit. Then, create your first Developers Console project and enable Prediction API in its API & auth section.
- Switch back to your newly created Google Apps Script and link it with your new Developers Console project through the
Resources/Developers Console Projectmenu.
We are done configuring. Now, there are only two functions to implement: one to train the model and the other to classify incoming mail.
GmailApp.getUserLabels() ❶ gets all labels that you defined in Gmail and disregards standard labels such as
All Mail or
Spam. Mails in Gmail are organized by threads, so once you get a handle on a label, you have to get all of its threads ❷, then grab individual mails under that thread. We'll use the first email of a thread for this simple exercise ❸.