As part of sending a bulk of emails on Gmail, I want to configure the Reply-To address depending on the recipient using Gmail's alias feature and Google Apps Script.
I've come across a problem that the reply-to settings in Gmail drafts created by the Google Apps Script is disabled (nullified) when attempting to send the created draft via the Gmail website, and wondered if anyone can help me with workarounds.
Reproducing
My script looks something like below. My Gmail account, for the sake of providing an example, is me@gmail.com:
var subject = 'An Eye-catching Email Subject';
var recipients = [{
email: 'mail1@sample.com',
replyTo: 'me+asia@gmail.com',
body: 'email text for mail1@sample.com'
},
{
email: 'mail2@example.com',
replyTo: 'me+europe@gmail.com'
body: 'email text for mail2@example.com'
}
// which goes on for an order of under 100 recipients
];
recipients.forEach(recipient => GmailApp.createDraft(recipient.email, subject, recipient.body, {
replyTo: recipient.replyTo
}));
When I open one of the created draft messages on the Gmail website, and then send the message by hitting the Send button, the sent email is set to reply to me@gmail.com and not the designated Reply-To aliases, like me+asia@gmail.com.
Alternatives
If I use the sendEmail() method instead of the createDraft() used above, everything works fine. The designated replyTo options are reflected in the actual emails sent.
The only reason that I use createDraft() instead of sendEmail() is that after the drafts are created, I want to make sure everything is alright before hitting the Send button, individually. I understand that I should probably just forget using createDraft(); I just can't figure out what Google intended to do with the replyTo option of createDraft(), and if anyone knows some other solution that I could take while sticking to createDraft(), I am more than grateful.