pythonmailgun

Error when submitting variables through Mailgun with Python


I'm trying to send mail through Mailgun with Python, in that instance I'm trying to push a variable alongside.

My code is the following:

requests.post("MailGun URL",
              auth=("api", "api-key"),
              data={
                  "from":"From_Mail",
                  "to":["To_Mail"],
                  "template":"template_name",
                  "subject":"Testing some things",
                  "h:X-Mailgun-Variables": {"firstname": "John"}
              })

If I use the above without "X-Mailgun-Variables" I'm not experiencing any problems, but with the above I get the following error message:

"delivery-status": {
        "code": 621,
        "message": "",
        "attempt-no": 1,
        "description": "Failed to decode variables",
        "session-seconds": 0
    }

What am I doing wrong?

Thanks in advance,


Solution

  • I found the solution myself - for future reference:

    "h:X-Mailgun-Variables": {"firstname": "John"}
    

    The above ss only for SMTP use.

    For API use:

    "v:firstname":"John"