When adding template data to an Azure Function i receive the error
Method not found: 'Void SendGrid.Helpers.Mail.SendGridMessage.SetTemplateData
Run.csx
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using SendGrid;
using SendGrid.Helpers.Mail;
using Microsoft.Azure.WebJobs.Host;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
// Variables
var apiKey = "{{insert your api key here}}";
var emailTo= "{{insert your email address here}}";
var templateId = "{{insert your SendGrid email teamplte id here}}";
// SendGrid
var from = new EmailAddress("[email protected]", "no reply");
var to = new EmailAddress(yourEmailAddress , "");
var templatedata = new EmailTemplateData()
{
EmailTo = emailTo,
Property1 = "//TODO"
};
var msg = new SendGridMessage();
msg.SetTemplateId(templateId);
msg.SetFrom(from);
msg.AddTo(to);
msg.SetTemplateData(templatedata);
var client = new SendGridClient(apiKey);
var response = await client.SendEmailAsync(msg);
// Console Stuff
return emailTo != null
? (ActionResult)new OkObjectResult($"Hello, {emailTo}")
: new BadRequestObjectResult("Please pass a email in the request body");
}
private class EmailTemplateData
{
[JsonProperty("EmailTo")]
public string EmailTo { get; set; }
[JsonProperty("Property1")]
public string Property1 { get; set; }
}
function.proj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SendGrid" Version="9.10.0"/>
</ItemGroup>
</Project>
function.json
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
}
]
}
Hello @mawiseman,
This should not be the case, I'ave added this to our backlog for further investigation. Thanks for bringing this issue to our attention.
With Best Regards,
Elmer
Is there any updates on this issue @thinkingserious ? I'm also having the same issue with the SendGrid azure functions binding
Hi @camilo86,
Can you please try using v9.11.0?
Thanks!
@thinkingserious Thanks! that fixed it