Setting mailgun variables in template using Python request

瘦欲@ 提交于 2021-01-29 13:38:33

问题


I want to set the value of a variable using a header attribute (as documented here). My Python code for sending:

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",
    })

I'm using the {{href_target}} in my template. While the online preview correctly displays the value of href_target (which is "test_href_target") instead of the handlebar syntax, this does not work when using the API.

Thanks!


回答1:


X-Mailgun-Variables header is only for adding this data via the SMTP API. You need to use the instructions for the HTTP API. Use:

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

And skip the headers.



来源:https://stackoverflow.com/questions/57905355/setting-mailgun-variables-in-template-using-python-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!