Organize Your Gmail Inbox with Google Apps Script

Managing a cluttered inbox can be overwhelming and time-consuming. Fortunately, Google Apps Script provides a powerful toolset that allows you to automate tasks within Gmail, making it easier to keep your inbox organized and streamlined. In this article, we will explore how to use Google Apps Script to organize your Gmail inbox efficiently.

Visit the Google Apps Script website, and create a new project by clicking on “New Project” from the main menu. This will open the Apps Script editor, where you can write and manage your scripts.

Label and Categorize Emails

The first step in organizing your inbox is to create labels and categorize your emails based on specific criteria. For example, you can create labels for “Project B,” “Project A,” “Important,” or any other custom categories you need. Use the following code to add labels to your emails:

				
					function categorizeEmails(){
let count = 100
const priorityAddresses = [
'important@example.com'
].map((address) => `from:${address}`).join(' OR ');

const labelName = "Important"; // Replace with your desired label name
const label = GmailApp.createLabel(labelName);

while (count > 0) {
const threads = GmailApp.search(`${priorityAddresses} -has:userlabels`, 0, 10)
count = threads.length
for(const thread of threads) {
thread.markImportant();
label.addToThread(thread);
}
}
}

				
			

Archive or Delete Old Emails

Having old and unnecessary emails in your inbox can lead to clutter. With Google Apps Script, you can automatically archive or delete emails that are older than a certain date. Here’s how:

				
					function archiveOldEmails() {
  const threads = GmailApp.search("in:inbox before:30d");
  for (const thread of threads) {
	thread.moveToArchive();
  }
}

				
			
				
					function deleteUnwantedMessages() {
let count = 100
const blockedAddresses = [
'spam1@example.com',
'spam2@example.com'
].map((address) => `from:${address}`).join(' OR ');
const searchQuery = `category:promotions OR category:social OR ${blockedAddresses}`;
while (count > 0) {
const threads = GmailApp.search(searchQuery, 0, 10);
count = threads.length
console.log(`Found ${count} unwanted threads`);
for(const thread of threads) {
console.log(`Moved to trash thread with id: ${thread.getId()}`)
thread.moveToTrash();
}
}
console.log("Deleting messages complete.");
}

				
			

Reply to Important Emails

It’s essential to respond promptly to crucial emails. With Google Apps Script, you can set up a script that automatically sends a reply to specific emails based on their sender or subject. Here’s a simple example:

				
					function autoReplyImportantEmails() {
  const importantSender = "important@example.com"; // Replace with the email address of the important sender
  const importantSubject = "Important Subject"; // Replace with the subject of important emails

  const threads = GmailApp.search(`is:unread from: ${importantSender} subject:${importantSubject}`);
  const replyMessage = "Thank you for your email. I will get back to you shortly.";

  for (const thread of threads) {
	threads[i].reply(replyMessage);
  }
}

				
			

Schedule Your Scripts

Once you have written your scripts, schedule them to run automatically at specific intervals. To do this, go to the Apps Script editor, click on the clock icon, and set up a time-driven trigger. You can choose to run the script daily, weekly, or at any custom frequency that suits your needs.

Conclusion

Organizing your Gmail inbox with Google Apps Script can significantly improve your productivity and reduce the time spent on email management. With the ability to label and categorize emails, archive or delete old messages, and automatically respond to important emails, you can maintain a clutter-free and efficiently organized inbox. Explore the power of Google Apps Script, and tailor your scripts to suit your unique email management requirements.

 

Read more about the latest tech trends in our blog.

Salesforce World Tour New York City

Salesforce World Tour New York City was December 13th and it was a fantastic experience for our team. It was a truly inspiring show and we’ll definitely be reflecting back on everything we learned for quite some time.

The keynote this year by Salesforce CMO Stephanie Buscemi was fascinating. She presented a vision of what Salesforce can do to help change the world that left us proud of the small part we’ve played in this process. Undoubtedly, Salesforce has a very strong vision for the future and the positive impact we can all have on the world but the keynote also gave us some great insights about the new tools coming to Salesforce that will make our clients happy too.

Salesforce Customer 360 was one of the star attractions of the keynote and Stephanie offered a number of different examples of what we’ll be able to do with it in the near future. They highlighted a number of different use cases for how Customer 360 allows Salesforce users to gather all essential data about customers in one place to make sure they’re taken care of at all times. What made us the most excited though was the awesome Einstein Voice demo by Sarah Aerni. As we’ve discussed in the past, we’ve had a hand in some work on Einstein Voice and it’s really exciting to see all that work coming together into something really powerful. The demo was a great example of Einstein Voice’s potential for Salesforce users and being able to ask Salesforce for important data and easily update client notes in the field all with your voice could be a real game-changer for a lot of users.

Cloudy’s Spot in the Office

As mentioned earlier Salesforce Customer 360 was one of the star attractions of the show and nowhere was that more evident than on the expo floor. Customer 360 was the centerpiece booth that everything else revolved around. The expo hall had a magnetic energy that made us all the more eager to see what everyone else was working on. Our team had a great time meeting people and even managed to find a new friend to bring home, Cloudy the Goat.

Our Friends at Copado

We were also fortunate enough to make it to a few sessions during the show. It was great to hear our friends and partners at Copado discuss their product and how it can help developers with release management. We’ll be working much more with Copado next year so stay tuned to find out more here on our blog soon. We also got to see an extended session discussing the strengths of Einstein Voice and what it can do for Salesforce users.

Einstein Voice Demo

Our day at Salesforce World Tour New York was fantastic and left the whole team feeling energized and excited about everything we’re working on heading into 2019. In a lot of ways, it was the perfect way to cap off the year. We got to see tons of friends and colleagues one last time before the end of the year, learned about some new products that we can look forward to, and reflected on everything that we accomplished over the past year. We were thrilled to be there and already planning for a number of events next year.

See You Next Year!

At Oktana, our team is growing fast check our current open positions