1
votes

Is it possible to change the recipient address when using the reply function in Google Apps Script?

I want to receive an email from a random email account, mark it with a label and when scheduled, run the following code to reply to a desired email address rather than the original sender. The reason I want to reply is to keep it in the same thread. I have tried nearly all variations of the following code and can't get it to work the way I want it to:

thread.reply("This is a message.", {
    htmlBody: "This is a message.",
    name: "My Name",
    recipient: "[email protected]",
    replyTo: "[email protected]",
    to: "[email protected]"
});
1

1 Answers

0
votes

If you're asking to generate a random email address and send a real email from that address... that's not possible.

However... you could set the replyTo optional parameter as a random address - though when users would try to reply to that thread they would get a bounce-back notification that the address could not be reached. However, the original sender (the non-random address) would still be visible in the original message.

If you look at the GmailApp docs (replying)/(sending), you'll notice a few limitations. The sender's address (from) must be a valid Alias, if you're sending mail from MailApp (Google Apps Script).

However, there are plenty of methods in the GmailMessage class such as getFrom() and getReplyTo() that would allow you to get/set the message's from/replyTo parameters and have them be the same value. That way, when you reply to a message you will always be in the same thread.