Forward email to a forwarding address manually using Apps Script

Viewed 24

I am trying to forward emails to a forwarding address, like a Gmail filter would, using Apps Script. The transferred email should therefore be an exact copy of the original one: same subject, body and from address (that's the tricky one).

My current code is a workaround and uses the 'usual' transfer function with some of its advanced parameters:

message.forward(
    'dude@example.com',
    {
        name: message.getFrom(),
        replyTo: message.getFrom(),
        subject: message.getSubject()
    }
)

The forwarded email however still appears as being sent from the forwarding address, and not the original sender address. This sometimes even messes up the Gmail threads...


[EDIT]
Aliases (see this question) are not the solution here since forwarding addresses can be a completely different account, especially in the context of a Google Workspace.

0 Answers
Related