Reputation: 38
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.
My script looks something like below. My Gmail account, for the sake of providing an example, is [email protected]
:
var subject = 'An Eye-catching Email Subject';
var recipients = [{
email: '[email protected]',
replyTo: '[email protected]',
body: 'email text for [email protected]'
},
{
email: '[email protected]',
replyTo: '[email protected]'
body: 'email text for [email protected]'
}
// 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 [email protected]
and not the designated Reply-To aliases, like [email protected]
.
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.
Upvotes: 1
Views: 435
Reputation: 201358
In my environment, I have experienced the same situation. At that time, I confirmed the following situations.
Reply-To
is removed from the header of the draft message, the draft message is sent.Reply-To
is included in the header.Reply-To
is sent using a script like GmailApp.getDraft(id).send()
, the message is sent by including Reply-To
in the header. This is the same situation with GmailApp.sendEmail()
.From above situation, as a simple workaround, how about sending the draft messages using a script as follows?
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.
in your question.When above workaround is reflected to the script, it becomes as follows.
function myFunction() {
GmailApp.getDrafts().forEach(e => e.send());
}
When the draft messages include some draft messages you don't want to send, for example, I think that the filter using the star can be also achieved. When you want to send the draft messages which have the star, you can also use the following script.
GmailApp.getDrafts().forEach(e => {
if (e.getMessage().isStarred()) e.send();
});
Upvotes: 1