Skip to content

Sending variables into templates pre-loaded into Mailgun #51

@JamieW87

Description

@JamieW87

I had an issue with trying to pass variables into a template that was in the Mailgun UI using the send() command.

Following the documentation for ts-mailgun, nothing would transfer the data across to the template when using the templateVars object in send().

After looking through the mailgun documentation, i found this example curl for sending an email.

curl -X POST https://api.mailgun.net/v3/example.com/messages 
      -F template="billing" 
      -H "X-Mailgun-Variables: {"firstName": "John",
"lastName": "Doe",
	"number": "12345",
	"data":"Mar 01, 2019",
	"amount1": "23.00",
	"amount2": "10.20",
	"total": "33.20"}"

Yet i noticed in dist/ts-mailgun.js that the send body is this:

// Create message parts
            var message = {
                from: _this.fromTitle + " <" + _this.fromEmail + ">",
                to: to,
                subject: subject,
                html: body,
                'recipient-variables': templateVars
            };

By changing recipient-variables to h:X-Mailgun-Variables I achieved the desired result and the variables passed through successfully.

I am happy to open a PR with the changes if that is suitable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions