Skip to content

Instantly share code, notes, and snippets.

@BehindTheMath
Last active September 11, 2016 02:31
Show Gist options
  • Select an option

  • Save BehindTheMath/f89cb4d7e9fe6cdef3547be11326a791 to your computer and use it in GitHub Desktop.

Select an option

Save BehindTheMath/f89cb4d7e9fe6cdef3547be11326a791 to your computer and use it in GitHub Desktop.
Google App Script to forward all emails with Kohl's Cash matching specific criteria
function KohlsCashFwd() {
//Define the variables
//The From field must include the entire text of the From field, including the name
var fromEmail = "Kohl's <[email protected]>";
var subject = "Nice work! Here's your Kohl's Cash.";
//Date format is yyyy/mm/dd
var afterDate = "2016/05/21";
var forwardEmail = "[email protected]";
//Find all threads with Kohl's Cash
var threads = GmailApp.search("from:" + fromEmail + " subject:" + subject + " after:" + afterDate);
//For each thread
for (i = 0; i < threads.length; i++) {
//Get its messages
var messages = threads[i].getMessages();
//For each message
for (x = 0; x < messages.length; x++) {
//Make sure this message has the correct From and Subject
if((messages[x].getFrom() == fromEmail) && (messages[x].getSubject() == subject)) {
//Forward the message
messages[x].forward(forwardEmail);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment