Forwarding e-mails if the specific keyword is found in the message body
The forwardEmails
function is able to forward e-mail messages, if a specific keyword is found in the body text to a prefixed e-mail ID. Be cautious about the number of iterations of the for
loop while testing your code so that you can avoid lot of messages forwarded in error:
/** * 1. Checks all unread inbox threads and messages. * * 2. If specific keyword found then forwards it to another * recipient. * * 3. Marks that message as Read. * */ function forwardEmails() { var recipient = "[[forward email id]]"; /* * Use keywords separated by '|'. * For example: "purchase | invoice" * */ var words = "keywords list"; var regExp = new RegExp(words,'g'); var len = GmailApp.getInboxUnreadCount(); for (var i = 0; i < len; i++) { // get 'i'th thread in inbox var thread = GmailApp.getInboxThreads(i,1)[0]; // get all messages in 'i'th thread var messages = thread.getMessages...