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(); ...

Get Learning Google Apps Script now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.