When I try to send an email using a template, and I add a Personalizations field with Substitutions, the response is always BadRequest.
When I comment the Substitutions dictionary it works. It doesn't work even if the Substitutions dictionary is empty.
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage()
{
From = new EmailAddress("email address", ""),
Subject = subject,
TemplateId = templateId,
Personalizations = new List<Personalization>
{
new Personalization()
{
Tos = new List<EmailAddress>()
{
new EmailAddress(email)
},
Substitutions = new Dictionary<string, string>()
{
//{"-name-", name},
//{"-email-", email},
//{"-subject-",subject},
//{"-message-", body},
//{"%url%", "www.google.com" }
}
}
}
};
var response = await client.SendEmailAsync(msg);
return (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK);
I'm using .net core 2.1 and Send grid is installed using nuget
Thanks
Hi there,
I have a feeling that you're using the new Dynamic Templates which don't take Substitutions but rather Dynamic_Template_date. Here's a doc on how to send emails with Dynamic Templates. Link here
Thanks,
Zach
Most helpful comment
Hi there,
I have a feeling that you're using the new Dynamic Templates which don't take Substitutions but rather Dynamic_Template_date. Here's a doc on how to send emails with Dynamic Templates. Link here
Thanks,
Zach