C# SendGrid动态模板包含空数据-.NET Core
我试图发送一封带有特定动态模板和数据的电子邮件。电子邮件已成功发送,但包含空数据。handle方法是Azure函数的一部分。最近我将Newtonsoft JSON更改为System.Text.JSON,这可能会导致一些问题 电子邮件: SendGrid动态模板配置: C#代码:C# SendGrid动态模板包含空数据-.NET Core,c#,asp.net-core,.net-core,sendgrid,sendgrid-templates,C#,Asp.net Core,.net Core,Sendgrid,Sendgrid Templates,我试图发送一封带有特定动态模板和数据的电子邮件。电子邮件已成功发送,但包含空数据。handle方法是Azure函数的一部分。最近我将Newtonsoft JSON更改为System.Text.JSON,这可能会导致一些问题 电子邮件: SendGrid动态模板配置: C#代码: public async Task Handle(SendEmailCommand command) { var client = new SendGridCl
public async Task Handle(SendEmailCommand command)
{
var client = new SendGridClient(emailConfig.SendGridApiKey);
var msg = new SendGridMessage();
msg.SetFrom(new EmailAddress(emailConfig.Sender));
msg.AddTo(new EmailAddress(command.To));
msg.SetTemplateId(command.SendGridTemplateId);
if (command.SendGridDynamicTemplateData != null)
{
var templateData = new TemplateData();
command.SendGridDynamicTemplateData.TryGetValue("topic", out var topic);
command.SendGridDynamicTemplateData.TryGetValue("email", out var email);
command.SendGridDynamicTemplateData.TryGetValue("name", out var name);
command.SendGridDynamicTemplateData.TryGetValue("message", out var message);
templateData.Topic = topic.ToString();
templateData.Email = email.ToString();
templateData.Name = name.ToString();
templateData.Message = message.ToString();
msg.SetTemplateData(templateData);
}
await client.SendEmailAsync(msg);
}
private class TemplateData
{
[JsonPropertyName("topic")]
public string Topic { get; set; }
[JsonPropertyName("email")]
public string Email { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; }
[JsonPropertyName("message")]
public string Message { get; set; }
}
我做错什么了吗?我也注意到了同样的事情。SendGrid API似乎无法识别
System.Text.Json
中的[JsonPropertyName]
属性。我不得不使用Newtonsoft.Json
中的[JsonProperty]
属性,以便在电子邮件中显示参数。我注意到了同样的事情。SendGrid API似乎无法识别System.Text.Json
中的[JsonPropertyName]
属性。我不得不使用Newtonsoft.Json
中的[JsonProperty]
属性来获取要显示在电子邮件中的参数。看起来SendGrid API无法与System.Text.Json一起正常工作,System.Text.Json是目前推荐的.NET Core序列化程序(比Newtonsoft.Json快)SendGrid API似乎无法与System.Text.Json一起正常工作,System.Text.Json是目前推荐的.NET核心序列化程序(比Newtonsoft.Json快)