
If you're like many people, you receive a lot of email. Sometimes important messages can get lost in the shuffle. Fortunately, you can use Google Apps Script to automatically create a task in the Google Tasks app when an email from a certain sender arrives in your Gmail inbox. In this tutorial, we'll walk through how to write a script that does just that.
To follow along with this tutorial, you'll need:
Before we can create tasks, we need to create a list to hold them. In Google Tasks, you can create lists to organize your tasks. To create a new list:
Make a note of the ID for your list. You'll need it later.
This will open a new tab with the Google Apps Script editor.
Here's the code to create a task in Google Tasks when an email from a certain sender arrives in your Gmail inbox:
function createTask(subject, body) {
const taskListId = 'YOUR_TASK_LIST_ID_HERE';
const taskList = Tasks.Tasklists.get(taskListId);
const task = {
title: subject,
notes: body
};
Tasks.Tasks.insert(task, taskList.id);
}
function getMessagesFromSender() {
const threads = GmailApp
.search('from:YOUR_SENDER_HERE subject:"YOUR_SUBJECT_HERE" is:unread');
for (const thread of threads) {
const messages = thread.getMessages();
for (const message of messages) {
if (message.isUnread()) {
const subject = message.getSubject();
const body = message.getPlainBody();
createTask(subject, body);
message.markRead();
}
}
}
}In the createTask function, replace 'YOUR_TASK_LIST_ID_HERE' with the ID of the list you created in step 1.
In the getMessagesFromSender function, replace 'YOUR_SENDER_HERE' with the email address of the sender you want to filter on, and replace 'YOUR_SUBJECT_HERE' with the subject line of the email you want to filter on.
This code will create a new task in your Google Tasks list for each unread email from the specified sender with the specified subject line.
To run the script:
The script will search your Gmail inbox for unread messages from the specified sender with the specified subject line. For each message it finds, it will create a new task in your Google Tasks list and mark the message as read.
In this tutorial, we've shown how to create a Google Task in the Tasks app when an email from a certain sender arrives in your Gmail inbox. This can help you stay organized and ensure that important messages don't get lost in your overcrowded inbox. Or you could just be on top of stuff, like a grown-up.