Last active
September 11, 2016 02:31
-
-
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
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 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