【发布时间】:2018-01-29 05:58:55
【问题描述】:
我正在尝试创建一个脚本,它将具有特定标签('send-to-test')的任何线程中的最新消息转发给特定的联系人组('fwd-test')。我主要基于StackExchange: How can I automatically forward Gmail emails when a label is applied?
到目前为止我想出的脚本如下:
function autofwd() {
//target mail label
var inlabel = 'send-to-test';
Logger.log("Target mail label is: " + inlabel);
//processed mail label
var outlabel = 'sent-to-test';
Logger.log("processed mail label is: " + outlabel);
//Retrieve contacts list to fwd to
var group = ContactsApp.getContactGroup('fwd-test');
var contacts = ContactsApp.getContactsByGroup(group);
var email = new String();
for (var i=0; i<contacts.length; i++)
email = contacts[i].getPrimaryEmail() + ',' + email;
Logger.log("email address list is: " + email);
//Find message threads matching the label variable and do something to each one
var threads = GmailApp.search('label:' + inlabel);
for (var i = 0; i < threads.length; i++) {
//isolate the last message in the thread and forward it using bcc field
var messages = threads[i].getMessages();
Logger.log("Working on message: " + messages);
messages[messages.length - 1].forward({bcc: email});
// add 'sent' label and remove 'send' label
var addlabel = GmailApp.getUserLabelByName(outlabel);
addlabel.addToThread(threads[i]);
var notlabel = GmailApp.getUserLabelByName(inlabel);
notlabel.removeFromThread(threads[i]);
}
}
问题是我想将电子邮件转发为密件抄送,但我无法让那行代码工作:
messages[messages.length - 1].forward({bcc: email});
失败并出现错误Invalid email: [object Object] (line 22, file "Code")
但如果我只使用 messages[messages.length - 1].forward(email); 就可以了
谁能帮我理解我做错了什么?
【问题讨论】: