Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

script google, GmailApp, Change subject and forward email

Long story short, emails which are coming from the specific email address I want to forward to another one with the modified subject. The body of the received email has two string which needs to be inserted in the subject line before forwarding. How would I modify the subject line and forward email by finding the occurrence of specific word either by contains/includes/indexOf or startsWith/endsWith logic.

The code I have so far:

function myFunction() {
// Forward first message of first inbox thread to recipient1 & recipient2, 
both @example.com
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var message = firstThread.getMessages()[0];
var from = message.getFrom();
var body= message.getPlainBody();
if(from = "email@email"){
message.forward("email2@email");
}
}

Comments