根据时间在Gmail中搜索电子邮件 [英] Searching emails in gmail based on time

查看:217
本文介绍了根据时间在Gmail中搜索电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一份来自gmail的昨天所有电子邮件的清单。我正在尝试使用谷歌应用程序脚本处理它,在我的收件箱中编写查询,然后使用GmailApp.search。之后:和之前:gmail中的搜索查询返回的结果不是预期的,因为查询基于SMTP服务器发送邮件的时间(它是谷歌的服务器)进行搜索。因此,在不同的时区,搜索产生不适合我的结果。有没有办法使用时间标准搜索Gmail,这样我可以适应时区差异?

I want a list of all yesterday's emails from gmail. I am trying to process it using google apps script, by writing a query on my inbox, and then using GmailApp.search. The after: and before: search query in gmail returns results that are not expected, since the query searches on the basis of the SMTP server time that the mail is sent from (which is google's server). Hence, being in a different time zone, the search yields inappropriate results to me. Is there a way to search gmail using a time criteria, so that I can accommodate for the time zone difference?

请注意,我的时区正确配置了本地时区,日历,gmail等,因此我在收件箱中看到的电子邮件的时间都是正确的。

Please note that the local time zone, calendar, gmail etc. is correctly configured for my timezone, so the emails that I see in my inbox are correctly timed. Only the search is creating an issue.

推荐答案

实际上,我经过一些试验和错误后发现了一种方法,确实有可能按时间搜索Gmail邮件。我注意到,在谷歌应用程序脚本返回的Date()是根据我的时区。下面的代码将返回收件箱中的所有前一天的电子邮件,假设新的Date()根据您的时区给出日期和时间。请注意,getTime()返回毫秒数,而较新/较旧的查询需要秒数。

I actually figured out a way after some trial and error, that it is indeed possible to search gmail emails by time. I noticed that the Date() returned in google apps script was according to my timezone. The code below will return all previous day's emails in inbox, assuming new Date() is giving the date and time according to your timezone. Note that getTime() returns milliseconds while the newer/older query expects seconds.

var month = new Date().getMonth();
var date = new Date().getDate();
var year = new Date().getFullYear();
var time1 = new Date(year, month, date, 0, 0, 0).getTime();
var time2 = time1 - 86400000;
var query = "newer:" + time2/1000 + " older:"  + time1/1000 + " in:inbox";
var conversations = GmailApp.search(query);

我希望它能帮助别人。

这篇关于根据时间在Gmail中搜索电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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