Sendgrid-csharp: .net core 2.1 Personalizations with Substitutions

Created on 23 Aug 2018  路  2Comments  路  Source: sendgrid/sendgrid-csharp

Issue Summary

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.

Steps to Reproduce

        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

unknown or a duplicate question

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

All 2 comments

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

Hello @avelinocanha-cloudware,

Please see this issue for progress. Thanks!

With Best Regards,

Elmer

Was this page helpful?
0 / 5 - 0 ratings