Closed mikalai-sauchanka closed 1 year ago
Hi, @mikalai-sauchanka, since you've mentioned "to[{index}].Vars" I assume that you are using V3 api to send the email.
Enable template language to be able to replace custom variables in the subject. This code works for me:
MailjetRequest request = new MailjetRequest
{
Resource = Send.Resource,
}
.Property(Send.FromEmail, "john.doe@mail.com")
.Property(Send.FromName, "Mailjet Pilot")
.Property(Send.Subject, "Hello, {{var:RecipientFirstName}}")
.Property(Send.TextPart, "Hello, {{var:RecipientFirstName}}")
.Property(Send.HtmlPart, "Hello, {{var:RecipientFirstName}}")
.Property(Send.Vars, new JObject {
{"RecipientFirstName", "John Doe"}
})
.Property(Send.Recipients, new JArray {
new JObject {
{"Email", "john.doe@mail.com"},
{"Name", "passenger 1"},
{"Vars", new JObject {
{"RecipientFirstName", "John Doe"}
}}
},
new JObject {
{"Email", "john.doe@mail.com"},
{"Name", "passenger 2"}
}
})
.Property(Send.MjTemplateLanguage, "True");
MailjetResponse response = await client.PostAsync(request);
Hi, @dmytrosvystun88. Thank you for your response!
Apparently I was using wrong syntax - square brackets instead of curly.
So far I managed to successfully got custom variables replaced in email body, but no in subject. I pass in "to[{index}].Vars".