I'm trying to use SendGrid's API to send Data to a Dynamic Template, and send that email to a customer. However, the email sends, but the data is never passed. Can anyone tell me what's wrong in my code? I don't see where my error is. I'm using C# .NET.
Here is my C# code
var Email_Client = new SendGridClient(apikey);
EmailAddress from = new EmailAddress(Me);
EmailAddress to = new EmailAddress(Customer);
var template = "x-xxxxxxxxxxxxxx";
var home = new house
{
Name = "test",
Price = price1
};
var email = MailHelper.CreateSingleTemplateEmail(from, to, template, home);
var emailResponse = await Email_Client.SendEmailAsync(email);
The odd thing is if I change my code to this:
var json = Newtonsoft.Json.JsonConvert.SerializeObject(new
{
homes = home
});
var email = MailHelper.CreateSingleTemplateEmail(from, to, template, json);
var emailResponse = await Email_Client.SendEmailAsync(email);
The email never gets sent.
The Email Template has HTML like this
<tbody>
{{#each homes}}
<tr>
<td style="width:200px;max-width:33.333%;"><img class="max-width" border="0" style="display:block;color:#000000;text-decoration:none;font-family:Helvetica, arial, sans-serif;font-size:16px;max-width:100% !important;width:100%;height:auto !important;" src="{{Img}}" alt="" width="200"></td>
<td style="width:200px;max-width:33.333%;"><div style="text-align: center;">{{Name}}</div>
</td>
<td style="width:200px;max-width:33.333%;"><div style="text-align: center;">{{Price}}</div></td>
</tr>
{{/each}}
</tbody>
Any guidance you can give will be very helpful. I've been wrapping my head around this for a while.