Created
December 15, 2015 18:40
-
-
Save erronjason/cac941d5160700628d1b to your computer and use it in GitHub Desktop.
Gmail auto-responder for use in https://script.google.com
This file contains hidden or 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
function AutoResponder(e) { | |
// Our email account that will be recieving: | |
var email_account = "[email protected]"; | |
// Search for subject: | |
var subject = "testsubject"; | |
// Send our response email | |
var threads = GmailApp.search("subject:(" + subject + ") label:unread to:(" + email_account + ")"); | |
for (var i = 0; i < threads.length; i++) { | |
// This is where further logic would go | |
var msg = threads[i].getMessages()[0]; | |
var word_count = msg.getBody().split(' ').length; | |
//Our response | |
var response_body = "Hey there, this is a test auto-responder.<br>\ | |
Number of words: " + word_count + "<br>\ | |
Original body: " + msg.getBody(); | |
// Respond to email | |
threads[i].reply("", {htmlBody: response_body, from: email_account}); | |
} | |
// Mark all as read | |
var threads = GmailApp.search("subject:(Contact Form) label:unread to:(" + email_account + ")"); | |
GmailApp.markThreadsRead(threads); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment