0

I work on problem sending main email and few reminders (not spam) after some time into same email address and thread. I use google app scripts and it has built-in GmailApp. So this is my messaging tool. I have few accounts that forward mails to one account that runs google scripts. Also these accounts are connected to that same account without checkmark in "Treat as an alias", if it is important.

Account settings

Task looked easy as when googling solutions I found statements that it is enough for emails to have same recipient email address and subject for google to sort it in same thread automatically. And in theory it should be fine with GmailApp.sendEmail() method like:

subject = "test subject"
// both emails are different @gmail 
GmailApp.sendEmail(email_to, subject, message_0, {html: message_0, from: email_from,  name: my_name})
// some delay
GmailApp.sendEmail(email_to, subject, message_1, {html: message_1, from: email_from,  name: my_name})

However emails come to gmail separately.

Then I figured out that you can actually use reply method + cc parameter. So after you sent first email. You look for thread and then you reply to yourself (cause your message is first and only in thread). It looks like this:

var threads = GmailApp.search('to:' + email_to + ' subject:"' + subject + '"');
var latest_thread = threads[0]
latest_thread.reply(message_0, {to: email_to, htmlBody: message_0, from: email_from, reply_to: email_to, cc: email_to})

*I tried with reply_to and without is same result.

Now new email actually appears in thread. However, yep, it has both fields "from" and "to" as my email and cc as recipient's email.

I want follow up emails to have "from" as my (sender's) email and "to" as recipient's email just like first email in thread does.

How can I achieve this funcionality?

1
  • From the documentation: "from String the address that the email should be sent from, which must be one of the values returned by getAliases()" Commented Feb 6 at 21:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.