Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How do I forward an email, including the original forwarded message and sender email in Gmail

$
0
0

I am trying to figure out how we can forward the original message and include the recipient email, full chain, so for example:

---------- Forwarded message ---------From: Ram Sam <test@example.org>Date: Mon, Apr 4, 2022 at 5:42 PMSubject: RE: about nurse appreciation dayTo: receiver@example.com <receiver@example.com>Receiver-Sure, that sounds great! Also, share any flyers, brochures, etc. We do currently usereward programs and this may be similar.Thank you,Ram Sam, PHR, SHRM-CP, FLWCS| Vice President of X2033 Main St, Address| X Healthcare Management, LLC

I am also labeling the ones that were forwarded so they don't get reforwarded on the second run. Here is what I have so far

function Forward() {  var imessagesForwarded = 0;  var label = 'LeadTest';  var doneLabel = GmailApp.getUserLabelByName('LeadFinished');  var threads = GmailApp.getUserLabelByName(label).getThreads();  var iforwarded = 0;  for (var i = 0; i < threads.length; i++) {    var it = threads.length;    if (iforwarded == im ) {      threads[i-1].addLabel(doneLabel);      threads[i-1].removeLabel(GmailApp.getUserLabelByName(label));    }    var messages = threads[i].getMessages();    var im = messages.length;    for (var j = 0; j < messages.length; j++) {        var email = messages[j];      if (!email.isStarred()) { //To keep track of processed emails, I star message when processed.        try {          forwardTo = 'alex@hypernovamarketing.com';          email.forward(forwardTo, {replyTo: email.getFrom(),subject: email.getSubject()});    messages[m].forward(rtm_email,{htmlBody: emailoptions + body , Attachment: attachment});          imessagesForwarded++;          email.star();          iforwarded++;        } catch(e) {          MailApp.sendEmail("alex@hypernovamarketing.com","Forward failed", "Errormsg:\n" + e.message);          continue;        }      } else {         iforwarded++;      }    }  }    if (iforwarded == im ) {    threads[i-1].addLabel(doneLabel);    threads[i-1].removeLabel(GmailApp.getUserLabelByName(label));  }}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>