使用 Python 请求在模板中设置 mailgun 变量

Setting mailgun variables in template using Python request

我想使用 header 属性设置变量的值(如 here 所述)。我的 Python 发送代码:

import requests
res = requests.post(
    "https://api.eu.mailgun.net/v3/mg.domain.de/messages",
    auth=("api", "xxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxxx-xxxxxxx"),
    headers = {
        "X-Mailgun-Variables": {"{'href_target': 'test'}"}
    },
    data={
        "from": "noreply@domain.de",
        "to": ["target@email.com"],
        "subject": "Testsubject",
        "template": "confirm-email-de",
    })

我在我的模板中使用 {{href_target}}。虽然在线预览正确显示 href_target 的值(即 "test_href_target")而不是 handlebar 语法,但这在使用 API.

时不起作用

谢谢!

X-Mailgun-Variables header 仅用于通过 SMTP API 添加此数据。您需要使用 HTTP API 的说明。使用:

data = {
    ...
    "v:href_target": "https://google.com"
}

并跳过 headers