问题
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