我想为某些参数设置一个gmail自带的过滤器。
基本上,我经常使用谷歌别名功能(电子邮件后的符号)。我想自动化创建一个过滤器的过程,该过滤器读取“to”行,然后查找一个“”。如果找到a“”,它将为“”后面的内容制作一个标签。然后,它将创建一个专用/本机过滤器,该过滤器将:跳过收件箱并应用“”后面的标签。
我已经浏览了gmail脚本,但还没有找到制作原生过滤器的方法。我知道这个功能可能刚刚实现。
function getTo() {
// Log the To line of up to the first 50 emails in your Inbox
var email = Session.getActiveUser().getEmail();
Logger.log(email);
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
Logger.log(messages[j].getTo()||email);
}
}
}
任何帮助都会很好。
解决方案:
// Creates a filter to put all email from ${toAddress} into
// Gmail label ${labelName}
function createToFilter(toAddress, labelName) {
// Lists all the filters for the user running the script, 'me'
var labels = Gmail.Users.Settings.Filters.list('me')
// Search through the existing filters for ${toAddress}
var label = true
labels.filter.forEach(function(l) {
if (l.criteria.to === toAddress) {
label = null
}
})
// If the filter does exist, return
if (label === null) return
else {
// Create the new label
GmailApp.createLabel(labelName)
// Lists all the labels for the user running the script, 'me'
var labelids = Gmail.Users.Labels.list('me')
// Search through the existing labels for ${labelName}
// this operation is still needed to get the label ID
var labelid = false
labelids.labels.forEach(function(a) {
if (a.name === labelName) {
labelid = a
}
})
Logger.log(labelid);
Logger.log(labelid.id);
// Create a new filter object (really just POD)
var filter = Gmail.newFilter()
// Make the filter activate when the to address is ${toAddress}
filter.criteria = Gmail.newFilterCriteria()
filter.criteria.to = toAddress
// Make the filter remove the label id of ${"INBOX"}
filter.action = Gmail.newFilterAction()
filter.action.removeLabelIds = ["INBOX"];
// Make the filter apply the label id of ${labelName}
filter.action.addLabelIds = [labelid.id];
// Add the filter to the user's ('me') settings
Gmail.Users.Settings.Filters.create(filter, 'me')
}
}
谢谢,安德
该功能似乎存在,但需要启用完整的Gmail API。
对于您的应用程序脚本,请按照https://developers.google.com/apps-script/guides/services/advanced的指示启用高级谷歌服务。当我第一次尝试使用Gmail。用户。设置。Filters.list('me')
调用时,我收到了一个授权错误,该错误给了我一个在开发者控制台中启用Gmail应用编程接口的链接,这相当于翻转一个开关。
启用此功能后,您可以编写一个脚本来制作过滤器,例如
js prettyprint-override">//
// Creates a filter to put all email from ${toAddress} into
// Gmail label ${labelName}
//
function createToFilter (toAddress, labelName) {
// Lists all the labels for the user running the script, 'me'
var labels = Gmail.Users.Labels.list('me')
// Search through the existing labels for ${labelName}
var label = null
labels.labels.forEach(function (l) {
if (l.name === labelName) {
label = l
}
})
// If the label doesn't exist, return
if (label === null) return
// Create a new filter object (really just POD)
var filter = Gmail.newFilter()
// Make the filter activate when the to address is ${toAddress}
filter.criteria = Gmail.newFilterCriteria()
filter.criteria.to = toAddress
// Make the filter apply the label id of ${labelName}
filter.action = Gmail.newFilterAction()
filter.action.addLabelIds = [label.id]
// Add the filter to the user's ('me') settings
Gmail.Users.Settings.Filters.create(filter, 'me')
}
function main () {
createToFilter('youruser+foo@gmail.com', 'Aliases/foo')
}
我不知道如何创建一个过滤器,可以追溯自动标记消息,因为谷歌似乎没有在他们的应用编程接口中公开这一点。
我为特定的传入电子邮件指定了不同的标签,并且在设置中禁用了线程(对话视图)。我可以在web应用程序中输入搜索,返回我想要的特定消息, 例如:“标签:客户01标签:报告” 然而,使用与API完全相同的过滤器会返回线程和谷歌确定的所有消息都属于同一对话的一部分(即使在现实世界中它们不是),这意味着我的脚本除了处理它应该处理的消息之外,还处理它不应该处理的消息。 例如:var threads=Gmail
使用谷歌应用脚本Gmail库,当我使用函数,API似乎将过去的一个段落拆分为多个段落,可能会使用字符限制。例如,我的电子邮件中有一段写道: 但当我在电子邮件中调用此功能时,它变成: 而且,当我在一个新的行定界符上拆分电子邮件文本,并进行一些清理,以使用我的输出创建一个数组时,我最终得到: 我查看了这篇Reddit帖子,它似乎处理了类似的问题。但是,我尝试了提出问题的人提出的解决方案: 但它并没有满
我使用一个简单的脚本来删除1天后所有标有“摄像头”的电子邮件。这已经奏效好几个月了。我没有改变它,但它突然停止工作。 该脚本仍有在我的Gmail上运行的权限,但已停止。 感谢任何建议。 脚本是; 谢了山姆
在继续使用GoogleApps脚本构建Google电子表格的过程中,我已经完成了获取Bittrex和Poloniex余额的工作,但无法使用Cryptopia。 下面是我与Bittrex将JSON对象数组映射到字符串的斗争的链接 以下是官方API链接:https://www.cryptopia.co.nz/Forum/Thread/256 以下是一些例子: https://www.cryptopia
我按照脚本以任何方式发布,在每周的特定时间发送Gmail自动回复?。然而,根据我目前的测试,我的Gmail账户在下班时间没有回复任何消息。 我做错了什么或不完整吗? 我所做的: 通过复制和粘贴在https://script.google.com/上创建了一个脚本。 保存脚本并测试它。它工作正常。在这里输入图像描述 任何提示都将不胜感激! 更新:我想知道为什么下面的脚本本身会导致“脚本函数未找到:m
我想使用谷歌应用程序脚本更新谷歌电子表格,并在我拥有的一系列日历发生更改时使用Gmail API发送电子邮件。 Google日历推送通知是否可以与Google App Script一起使用,或者是否需要其他某种平台? 我愿意学习任何必要的东西。我知道需要一个域名来接收通知。 我感谢你的帮助!