Sendgrid-csharp: SendGrid C# API template substitution issue

Created on 5 Sep 2018  路  6Comments  路  Source: sendgrid/sendgrid-csharp

I got transaction template with following subject: Request at {{receiveDate}}. But I couldnt send substitution to it.

I am trying following code:

         var msg = new SendGridMessage { };
        msg.From = new EmailAddress(emailFrom.Address.ToLower(), emailFrom.DisplayName);
        msg.AddTo(new EmailAddress("[email protected]"));
        msg.AddSubstitution("{{receiveDate}}","date");
        msg.TemplateId = ID;
        var result = client.SendEmailAsync(msg).Result;

but got error: `result.StatusCode == BadRequest'. How could I fix that?
When I comment line with substitution - everything works fine.

unknown or a waiting for feedback question

Most helpful comment

Hello @Seekeer,

Please upgrade to version 9.10.0 of this SDK and see this example.

Thanks!

With Best Regards,

Elmer

All 6 comments

@Seekeer look at issue #716

@Leeemons as far as I understand its about dynamic templates. But I want to use templates created on server.

Hello @Seekeer,

Please upgrade to version 9.10.0 of this SDK and see this example.

Thanks!

With Best Regards,

Elmer

None of these examples work. This library is a mess.

Hello @GiorgioG,

Do you mind sharing your code so that I may try to reproduce your issue? Thanks!

With Best Regards,

Elmer

It works for me:

msg.SetTemplateData(new { receiveDate = date });

I think it's more gracefully than method from sample.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogacg picture bogacg  路  3Comments

eat-sleep-code picture eat-sleep-code  路  3Comments

digime99 picture digime99  路  5Comments

LorenDorez picture LorenDorez  路  4Comments

shoter picture shoter  路  4Comments