Trying to use transactional template with azure function sendgrid integration (javaScript) , I'm sending the following object (removed email address etc.):
const message =
{
"personalizations":[
{
"to":[
{
"email":"[MY_EMAIL]",
"name":"Rotem"
}
],
"dynamic_template_data":{
"rotem_test1":"wow"
}
}
],
"from":{
"email":"[FROM_EMAIL]",
"name":"name"
},
"reply_to":{
"email":"[REPLY_EMAIL]",
"name":"name"
},
"template_id":"[CORRECT_TEMPLATE_ID]",
"tracking_settings":{
"click_tracking":{
"enable":true
}
}
}
context.done(null,message);
also tried using context.done(null,JSON.stringify(message))
with the same result:
I get an email from the correct template but without any substitution.
when sending the exact same object using the https://api.sendgrid.com/v3/mail/send
API using postman everything works well.
would love to get help here as for what I'm doing wrong on my azure function.
You did everything correctly as you can receive email as expected.
Problem is caused by the SDK version. Property dynamic_template_data
has just been added in latest 9.10.0 Sendgrid C# SDK, but the binding extension still uses old version, which has no idea what dynamic_template_data
is.
For 2.x function(Check Function app settings on Azure portal, see Runtime version: 2.xxx (~2)), we can install new version SDK manually before the extension is updated.
If you develop locally
<PackageReference Include="Sendgrid" Version="9.10.0" />
.func extensions install
to restore packages.Else on Azure portal
<PackageReference Include="Sendgrid" Version="9.10.0" />
and Save the changes.dotnet build extensions.csproj -o bin --no-incremental --packages D:\home\.nuget
Build succeeded
, start the function app.For 1.x function(Runtime ~1), I am afraid we have to manually send email using with sendgrid node module, Sendgrid vesion in 1.x function is locked therefore can't be updated.