我将此代码用于 Gmail,但现在我希望为 Google 收件箱做类似的事情。问题是谷歌收件箱不支持标签,所以我必须想出另一个解决方案。也许以某种方式每 5 分钟检查一次容器内的电子邮件然后转发它们?还有其他建议吗?
function autoForward() {
var label = 'ForwardThis';
var recipient = 'domain@forward.domain.com';
// if the script runs every 5 minutes; change otherwise
var interval = 5;
var date = new Date();
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('label:' + label + ' after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
var from = messages[i].getFrom();
var subject = messages[i].getSubject();
var to = messages[i].getTo();
var attachment = messages[i].getAttachments();
var body = messages[i].getBody();
for (var j = 0; j < messages.length; j++) {
var emailoptions = (
"---------- Forwarded message ----------" + '<br>' +
'From: ' + from + "<'" + from.replace(/^.+<([^>]+)>$/, "$1") + "'>" + '<br>' +
'Date: ' + date + '<br>' +
'Subject: ' + subject + '<br>' +
'To: ' + to + "" + '<br>' + '<br>' + '<br>'
);
messages[j].forward(recipient,{htmlBody: body + emailoptions, Attachment: attachment});
}
}
}