【问题标题】:Can't delete MailGun bounces?无法删除 MailGun 退回邮件?
【发布时间】:2018-06-19 06:10:53
【问题描述】:

在 MailGun 后端,我注意到“未投递到以前退回的地址”错误:

这可能是因为当时电子邮件地址尚未正确设置,但现在已正确设置。因此,我想从之前退回的地址列表中删除地址kurt@hicleo.com

https://documentation.mailgun.com/en/latest/api-bounces.html#bounces 之后,我为我们的发件人域mg.startwithlucy.com 实现了get_bounces() 方法:

    In [1]: import requests

    In [2]: def get_bounces():
       ...:     return requests.get('https://api.mailgun.net/v3/mg.startwithlucy.com
       ...: /bounces', auth=('api', '<our_api_key>') 
       ...:     )
       ...: 

    In [3]: response = get_bounces()

    In [4]: response.status_code
    Out[4]: 200

    In [6]: import json

    In [7]: content = json.loads(response.content)

    In [14]: next(item for item in content['items'] if item['address'] == 'kurt@hicleo.com')
    Out[14]: 
    {'MessageHash': '0f35b8112739c23d996bece18755de105a8422ad',
     'address': 'kurt@hicleo.com',
     'code': '550',
     'created_at': 'Thu, 07 Jun 2018 17:48:28 UTC',
     'error': 'No Such User Here'}

接下来,我定义了一个delete_bounce(address) 函数并为kurt@hicleo.com 调用它。但是,我仍然在get_bounces() 的结果中看到相应的电子邮件地址:

In [21]: def delete_bounce(address):
    ...:     return requests.delete(f'https://api.mailgun.net/v3/mg.startwithlucy.com/{address
    ...: }', auth=('api', '<our_api_key>'))
    ...:     

In [22]: delete_response = delete_bounce('kurt@hicleo.com')

In [23]: delete_response.status_code
Out[23]: 200

In [24]: delete_response.content
Out[24]: b'Mailgun Magnificent API'

In [25]: response = get_bounces()

In [26]: response.status_code
Out[26]: 200

In [27]: content = json.loads(response.content)

In [28]: kurt_bounces = [item for item in content['items'] if item['address'] == 'kurt@hicleo.
    ...: com']

In [29]: kurt_bounces
Out[29]: 
[{'MessageHash': '0f35b8112739c23d996bece18755de105a8422ad',
  'address': 'kurt@hicleo.com',
  'code': '550',
  'created_at': 'Thu, 07 Jun 2018 17:48:28 UTC',
  'error': 'No Such User Here'}]

这里出了什么问题?在我看来,这似乎是 API 参考中指令的正确 Python 实现:

【问题讨论】:

    标签: python mailgun email-bounces


    【解决方案1】:

    您似乎已将bounces(位于域和地址之间)排除在 URL 之外。

    【讨论】:

      【解决方案2】:

      此外,使用 MailGun 的 UI,在“抑制”选项卡中可以轻松删除退回邮件,如下所示:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-09-28
        • 2015-04-08
        • 2017-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多