Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AwaitingReply
function label_awaiting_reply() {
var emailAddress = Session.getEffectiveUser().getEmail();
Logger.log(emailAddress);
var EMAIL_REGEX = /[a-zA-Z0-9\._\-]+@[a-zA-Z0-9\.\-]+\.[a-z\.A-Z]+/g;
var label = GmailApp.createLabel("AwaitingReply");
var d = new Date();
d.setDate(d.getDate() - 7);
var dateString = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate();
threads = GmailApp.search("in:Sent after:" + dateString);
for (var i = 0; i < threads.length; i++)
{
var thread = threads[i];
var lastMessage = thread.getMessages()[thread.getMessageCount()-1];
lastMessageSender = lastMessage.getFrom().match(EMAIL_REGEX)[0];
if (lastMessageSender != emailAddress)
{
thread.addLabel(label);
Logger.log(lastMessageSender);
}
}
}
function doGet(e){
label_awaiting_reply();
}
@colinloretz

This comment has been minimized.

Copy link
Owner Author

@colinloretz colinloretz commented Mar 2, 2014

Disclaimer: I did not write the above code. I believe I ran across it on Fred Wilson's blog years ago when he was talking about email productivity but haven't managed to find who and where it was posted.

What it does

Marks an emails that you have received but you have not responded to with an "AwaitingReply" label in gmail. Sometimes having "unread" and "read" emails isn't enough.

It's not perfect but it will help you find some needles in the haystack when you're dealing with large email loads. When I was in TechStars we were doing a lot of follow up emails with mentors and investors and we used this frequently to make sure we didn't have any we were missing.

How to use it

  1. Obviously read the code and make sure you're comfortable with what it does and how it executes. Read more about Google Scripts if needed.
  2. Go to Google Docs. Go to Create -> Script
  3. Add the above code as the only file in the script.
  4. Click on Publish -> Deploy as a web app
  5. Select "Execute the app as me".
  6. Take the resulting Macro URL and add it as a bookmark in your bookmark bar. Voila.. Awaiting Reply button you can use anywhere.

Edit this and use it as you you need. This is a good example for one use case but you can use the attached code to create labels for other situations as well, such as tagging all emails that you are waiting to hear back from.

@colinloretz

This comment has been minimized.

Copy link
Owner Author

@colinloretz colinloretz commented Mar 2, 2014

Also, the fact that this whole thing works was kind of amazing to me since it never appears to ask for permission to Google Mail from Google Docs....

@sbeckeriv

This comment has been minimized.

Copy link

@sbeckeriv sbeckeriv commented Mar 3, 2014

To get scripts go to connect more apps when you click create and search for script.

I got lost after step 5.

I clicked "update" then

Resources -> current projects triggers

From there I set it to run every hour. I also ran it manually once. When I manually ran it it asked me for permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment