我有一个 Mailgun 应用程序,其传入路由按以下方式设置:
match_recipient('me@example.com')
store(notify='https://www.example.com/endpoint')
在某些时候,我通过 DNS 提供商使用 301 重定向将域从 www.example.com
切换到 www.example2.com
(阅读:我无法访问日志..)而不更改 Mailgun 路由。
在几天的时间里,我在日志中发现了一堆永久性错误,因为 webhook 似乎不遵循重定向。
现在,我想尝试检索这些存储的消息,但我找不到获取原始 ID 的方法。
以下是 Mailgun 事件日志中存储的内容:
{
"severity": "permanent",
"tags": [],
"delivery-status": {
"retry-seconds": 14400,
"message": "<html><body>You are being <a href=\"https://www.example2.com/endpoint\">redirected</a>.</body></html>",
"code": 301,
"description": "<html><body>You are being <a href=\"https://www.example2.com/endpoint\">redirected</a>.</body></html>",
"session-seconds": 0.7563347816467285
},
"envelope": {
"targets": "https://www.example.com/endpoint",
"transport": "http",
"sender": "postmaster@example.com"
},
"log-level": "error",
"id": "dffZ3qigQpyKGNdwhfj26A",
"campaigns": [],
"reason": "old",
"user-variables": {},
"flags": {
"is-routed": null,
"is-authenticated": true,
"is-callback": true,
"is-system-test": false,
"is-test-mode": false
},
"timestamp": 1430473028.303534,
"message": {
"headers": {
"to": null,
"message-id": "20150430214155.10820.14949@example.com",
"from": "postmaster@example.com",
"subject": null
},
"attachments": [],
"recipients": [
"https://example.com/endpoint"
],
"size": 47467
},
"recipient": "https://example.com/endpoint",
"event": "failed"
}
(1) 上面的 id
似乎代表事件 ID,我认为这是无关紧要的,而消息 ID 似乎是 20150430214155.10820.14949
。
(2) 在典型的 Webhook 成功场景中,发布到服务器的消息包含一个用于检索消息的回调 URL,如下所示:
https://api.mailgun.net/v2/domains/www.example.com/messages/WyI4MzNheDUxMmRjIiwgWyI0ZWFiNWM1Mi05Zjg4LTRkMjctYjdhMS04ZTM3Y2E3ZDJmNTkiXSwgIm1haWxndW4iLCAib2xkY29rZSJd
这是以下内容的 Base64 编码消息(所有 UID 均已修改):
["833ax512dc", ["4eab5c52-9f88-4d27-b7a1-8e37ca7d2f59"], "mailgun", "oldcoke"]
有没有办法使用消息 ID 20150430214155.10820.14949 构造存储消息检索 URL?
最佳答案
这对于 AmitA 来说可能有点太晚了的需要,但如果其他人想知道获取该检索 URL 的方法,我的方法是使用事件 API:
GET/events?message-id={您的消息 ID}
这将返回一个响应,并在“items”键下显示结果列表。这些项目将在“storage”键下具有该 URL,如“url”。
因此,如果 response
是来自该 GET 调用的响应,则第一个响应的 URL 将在 response['items'][0]['storage'][ 处找到'url']
。
我希望对那里的人有所帮助!
关于Mailgun:有没有办法检索 Webhook 调用放弃的存储消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30017420/