Gmail定时过滤器可在上午8点至下午5点之间删除邮件

时间:2014-08-04 15:00:41

标签: email gmail-api

如何在gmail中设置内容以在上午8点到下午5点之间删除与gmail过滤器匹配的消息

我当时认为可以通过谷歌应用程序脚本来实现,并且想知道是否有人已经做过这样的事情了吗?

1 个答案:

答案 0 :(得分:1)

我会遍历顶级主题(不幸的是最多20个)并检查它们上的日期时间戳,然后你可以使用相对简单的delete api删除它们。

    CLIENT_SECRET_FILE = 'client_secret.apps.googleusercontent.com.json'
    OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.compose'
    STORAGE = Storage('gmail.storage')
    flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
    http = httplib2.Http()
    credentials = STORAGE.get()
    if credentials is None or credentials.invalid:
        credentials = run(flow, STORAGE, http=http)
    http = credentials.authorize(http)
    gmail_service = build('gmail', 'v1', http=http)
    threads = gmail_service.users().threads().list(userId='me', maxResults=1).execute()
    if threads['threads']:
        for thread in threads['threads']:

我在这里为您编写的代码为您提供了简单的部分,您需要做的就是检查该特定消息的date-time,然后决定是否要{{3}它。