最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google apps script - Correct 'from' field for sequential email sending in a thread using GmailApp - Stack Overfl

programmeradmin0浏览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.

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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论