Blog
Back to Blog
Streamline Your Productivity: Convert Emails to Tasks with this Simple Script
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.
Prerequisites
To follow along with this tutorial, you'll need:
- A Gmail account
- A Google account
- Access to Google Apps Script
Step 1: Create a Google Tasks list
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:
- Open the Google Tasks app by going to https://tasks.google.com/
- Click the three horizontal lines in the upper left corner of the screen
- Click Create new list
- Name your list
Make a note of the ID for your list. You'll need it later.
Step 2: Create a script
- Open Google Drive by going to https://drive.google.com/
- Click New
- Click More
- Click Google Apps Script
This will open a new tab with the Google Apps Script editor.
Step 3: Write the script
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.
Step 4: Run the script
To run the script:
- Click Run in the toolbar
- Click getMessagesFromSender
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.
Conclusion
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.