【问题标题】:How to block a sender using Gmail API?如何使用 Gmail API 阻止发件人?
【发布时间】:2021-05-14 00:00:09
【问题描述】:

在我的应用程序中,我目前正试图通过 Gmail 的 API 阻止使用 python 应用程序的用户。

目前我已尝试使用过滤器将电子邮件移至垃圾邮件

GMAIL.users().messages().modify(userId=user_id, id=m_id,body={ 'addLabelIds': ['SPAM']}).execute()

但我仍会在收件箱中收到来自发件人的未来电子邮件。

如何使用 Gmail API 将发件人未来的电子邮件放入垃圾邮件文件夹?

(基本上屏蔽发件人,就像Gmail网络应用中的功能)

这可能吗,使用过滤器?

【问题讨论】:

  • 你检查过文档是什么让你认为 gmail api 支持这样的东西吗?

标签: python gmail-api google-api-python-client


【解决方案1】:

您尚未为此帐户创建过滤器,您刚刚修改了来自该帐户的所有电子邮件的标签。

要创建过滤器,您必须使用Method: users.settings.filters.create

你有python上的例子here:

label_id = 'Label_14' # ID of user label to add
filter = {
    'criteria': {
        'from': 'cat-enthusiasts@example.com'
    },
    'action': {
        'addLabelIds': [label_id],
        'removeLabelIds': ['INBOX']
    }
}
result = gmail_service.users().settings().filters().\
    create(userId='me', body=filter).execute()
print 'Created filter: %s' % result.get('id')

【讨论】:

    猜你喜欢
    • 2014-07-22
    • 2017-12-21
    • 1970-01-01
    • 2015-07-22
    • 2014-09-01
    • 1970-01-01
    • 2019-06-21
    • 2017-03-21
    • 2019-03-08
    相关资源
    最近更新 更多