收到电子邮件时触发的 Google gmail 脚本 [英] Google gmail script that triggers on incoming email

查看:19
本文介绍了收到电子邮件时触发的 Google gmail 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读 gmail 插件.当您打开电子邮件时,它们会触发上下文触发器.

I've been reading through gmail addons. They have contextual triggers that trigger when you open an email.

当我收到电子邮件时,是否可以触发服务?我能找到的最好的是 unconditional 但这仅在打开电子邮件时触发.

Is it possible to trigger a service when an email is received by me? Best I can find is unconditional but that only triggers when the email is opened.

推荐答案

你不能为每封邮件都创建一个触发器,但是你可以做类似的事情 如本答案所述.

You can't create a trigger for every email, however you can do something similar as described in this answer.

例如,您可以:

  1. 设置一个过滤器,在您要处理的传入电子邮件上放置一个特殊标签.

  1. Set up a filter that puts a special label on incoming emails that you want to process.

设置每 10 分钟甚至每分钟运行一次的重复脚本.在脚本中,您可以提取所有具有给定标签的电子邮件,并相应地处理它们,完成后删除标签.

Set up a reoccurring script that runs every 10 minutes, or even every minute. In the script, you can pull all of the emails that have the given label, and process them accordingly, removing the label when you are done.

function processEmails() {
  var label = GmailApp.getUserLabelByName("Need To Process");
  var threads = label.getThreads();  
  for (var i = threads.length - 1; i >= 0; i--) {
    //Process them in the order received
    threads[i].removeLabel(label).refresh();
  }
}

然后您可以在 基于时间的触发器上设置它它可以随心所欲地运行.

You can then set this on a time based trigger to have it run as often as you would like.

如果您想跟踪已处理的电子邮件,您可以创建另一个已处理"标签,并在处理完成后将其添加到邮件中.

If you want to keep track of the emails you have processed, you can create another "processed" label and add that to the message when you are done processing.

这篇关于收到电子邮件时触发的 Google gmail 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆