简体   繁体   English

带有Gmail的Google Apps脚本:搜索,重命名和转发特定邮件

[英]Google Apps Script with Gmail: Search, Rename and Forward specific mails

I'm curious to learn if the following scenario can be addressed using Google Apps Script (or perhaps another method?). 我很想知道是否可以使用Google Apps脚本(或其他方法)解决以下情况。 Here's the scenario I'm dealing with. 这是我正在处理的方案。

Perform a specific subject line search when new messages are received. 收到新消息时,请执行特定的主题行搜索。 For example: 例如:

  • ({subject:(keyword1 keyword2 keyword3) subject:(keyword1 keyword4 keyword5)}) ({主题:(keyword1 keyword2 keyword3)主题:(keyword1 keyword4 keyword5)})

If matched, perform the following actions: 如果匹配,请执行以下操作:

  1. Modify the subject line to include "#action" 修改主题行以包括“ #action”
  2. Forward this newly renamed mail to another email address 将此新重命名的邮件转发到另一个电子邮件地址

Bonus points if I can somehow then label the original email, and archive said original mail (removing it from my inbox) in one fell swoop. 如果我能以某种方式加上标签,就可以加分,然后将所说的原始邮件(从收件箱中删除)存档一次。

Help is most appreciated. 非常感谢您的帮助。

As per the Gmail API , you can only modify the labels of a Gmail message but not the subject or body. 根据Gmail API ,您只能修改Gmail邮件的标签,而不能修改主题或正文。

To forward an email to another account, or to archive an email, you could use the message.forward() and moveThreadsToArchive() methods in Google Apps Script. 要将电子邮件转发到另一个帐户或将电子邮件存档,可以使用Google Apps脚本中的message.forward()和moveThreadsT​​oArchive()方法。

function archiveMessages() {
  var query = 'label:archiveme';
  var threads = GmailApp.search(query);      
  GmailApp.moveThreadsToArchive(threads);
  threads.forEach(function(thread) {
    thread.getMessages().forEach(function(message) {
          message.forward("recipient@example.com");
    });
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM