Last active
July 1, 2023 05:37
-
-
Save rboyd/5027691 to your computer and use it in GitHub Desktop.
google apps script to archive and autoreply to long emails.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* paste into http://script.google.com | |
run periodically (e.g. every 5 minutes) with a timer by selecting 'Resources' > 'current project's triggers...' | |
*/ | |
function filterLongEmails() { | |
var num_messages = 1; // will be applied to the last n messages. Google allows up to 500 | |
var word_limit = 50; | |
var subj = "Shorter emails will get read."; | |
var body = "Dear friends, I value my time and yours but I appreciate it if you can keep your emails under " + word_limit + " words. Please edit and resend."; | |
// get the last 'num_messages' from inbox | |
var threads = GmailApp.getInboxThreads(0, num_messages); | |
for (var i = 0; i < threads.length; i++) { | |
if (threads[i].getMessageCount() == 1) { | |
var msg = threads[i].getMessages()[0]; | |
var word_count = msg.getBody().split(' ').length; | |
if (word_count > word_limit) { | |
MailApp.sendEmail(msg.getFrom(), subj, body); | |
GmailApp.moveThreadToArchive(threads[i]); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment