sendgrid html text,Can you send HTML in the dynamic template data

作者在尝试通过SendGrid API发送带有HTML内容的电子邮件时遇到问题。他们能够成功发送模板数据,但无法将HTML片段正确地插入到模板的占位符中。目前,占位符被显示为纯文本而不是作为HTML渲染。作者询问如何实现类似Razor视图引擎中的`Html.Raw()`方法的效果,即让HTML内容在邮件中以富文本形式呈现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Issue Summary

I'm currently using the workaround for sending template data to the API and it seems to be working fine. The only thing I can't figure out is how I can send an HTML fragment as a substitution.

Steps to Reproduce

So, I am using this as part of my email service:

var obj = (JObject)JsonConvert.DeserializeObject(messageJSON);

var personalizations = (JArray)obj["personalizations"];

foreach (var personalization in personalizations.Cast())

{

var substitutions = personalization.Property("substitutions");

substitutions.Replace(new JProperty("dynamic_template_data", substitutions.Value));

}

var dynamicMessage = obj.ToString();

await client.RequestAsync(SendGridClient.Method.POST, dynamicMessage, null, "mail/send");

Before that I set the substitutions which will be converted to the dynamic_template_data.

If I use something like:

msg.AddSubstitution("Content","This is a test
test");

The {{Content}} placeholder in my template is rendered with the
visible in the test string.

How can I get the template to replace the placeholder with my html content and render it as html?

(Like what the Html.Raw() method does in razor)

Thanks,

Jason

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值