如何在SendGrid电子邮件中插入动态html块?
我正在使用SendGrid web API v3。正在尝试生成包含多个收件人的个性化设置对象。每个收件人有一封电子邮件,其中包含与当前收件人相关的数据(通过替换) 示例:如何在SendGrid电子邮件中插入动态html块?,html,email,sendmail,sendgrid,Html,Email,Sendmail,Sendgrid,我正在使用SendGrid web API v3。正在尝试生成包含多个收件人的个性化设置对象。每个收件人有一封电子邮件,其中包含与当前收件人相关的数据(通过替换) 示例: personalizations: [{ to: [{email: 'example@mail.com'}], subject: 'Hello, :name!', substitutions: {':name': 'John', ':info_section_html':'<p&
personalizations: [{
to: [{email: 'example@mail.com'}],
subject: 'Hello, :name!',
substitutions: {':name': 'John', ':info_section_html':'<p>Some useful block1</p><p>Some useful block2</p>'}
},
{
to: [{email: 'example@mail.com'}],
subject: 'Hello, :name!',
substitutions: {':name': 'John', ':info_section_html':'<p>Some useful block1</p><p>Some useful block2</p><p>Some useful block3</p><p>Some useful block4</p><p>Some useful block5</p><p>Some useful block6</p>'}
}
],
from: {email: 'send@example.com'},
content: [{type: 'text/html', value: 'Hello, :name! </br> Here are your very usefull info</br> :info_section_html'}]
个性化:[{
收件人:[{电子邮件:'example@mail.com'}],
主题:“你好,:name!”,
替换:{:name':'John',':info_section_html':'一些有用的block1一些有用的block2'
},
{
收件人:[{电子邮件:'example@mail.com'}],
主题:“你好,:name!”,
替换:{:name':'John',':info_section_html':“一些有用的block1一些有用的block2一些有用的block3一些有用的block4一些有用的block5一些有用的block6}”
}
],
发件人:{电子邮件:'send@example.com'},
内容:[{type:'text/html',value:'Hello,:name!这是您非常有用的信息:info\u section\u html'}]
当替换时:info\u section\u html
有很多这样的块,它超过了10000字节的限制。我的块的HTML比示例中的要多得多。每个收件人可以有不同数量的块,这就是为什么我不能将它们包含在内容属性中
我也在考虑sections属性,在这里我可以传递我的info\u section\u HTML
。但无法以替换方式传递数据数组
有人能建议如何克服这个问题吗?我知道这个问题来得很晚,但我也面临同样的问题,找不到答案,所以我想还是把它贴在这里比较有用: 如图所示: 模式“substitution_tag”:“value to substitute”下的键/值对集合。所有都假定为字符串。除了主题和回复参数外,这些替换将应用于电子邮件正文的文本和html内容。每个personalization对象的替换总大小不能超过10000字节 所以这里没什么可做的 对于这种用法,Sendgrid还有另一个功能,称为节(也可以查看上面的链接)。它们的工作原理几乎类似于
替换
,只是它们链接到整个邮件,而不是每个替换
它们可以与替换一起使用
,以实现上述行为
正如mbernier在这里所说:
您可以这样使用它们:
"personalizations: [
{
"to: [{"email":"bob@example.com"}],
"substitutions": {
"[%product_info%]": "[%has_product%]",
},
},
{
"to":[{"email":"bob@example.com"}],
"substitutions": {
"[%product_info%]": "[%no_product%]",
},
}],
"content": [
{
"type": "text/plain",
"value": "We just wanted to tell you that we appreciate you being a long time customer! [%product info%]"
}],
"sections": {
"[%has_product%]": "Also, thanks for ordering:<br />[%product_section%].<br /> Are you ready to order again!?",
"[%no_product%]": "You haven't ordered in a while, but we'd love it if you came back and saw our new products!"
}
“个性化:[
{
收件人:[{“电子邮件”:bob@example.com"}],
“替换”:{
“[%product\U info%]”:“[%has\U product%]”,
},
},
{
“发送至”:[{“电子邮件”:”bob@example.com"}],
“替换”:{
“[%product\U info%]”:“[%no\U product%]”,
},
}],
“内容”:[
{
“类型”:“文本/普通”,
“价值”:“我们只是想告诉您,我们感谢您成为长期客户![%product info%]”
}],
“章节”:{
“[%has_product%]”:“另外,感谢您的订购:
[%product_section%]。
您准备好再次订购了吗!?”,
“[%no_product%]”:“您已经有一段时间没有订购了,但是如果您回来看看我们的新产品,我们会很高兴的!”
}
这里最重要的是,应该通过替换标记添加节
希望这能有所帮助我知道这来得很晚,但我也面临同样的问题,无法找到答案,所以我想还是把它贴在这里比较有用: 如图所示: 模式“substitution_tag”:“value to substitute”下的键/值对集合。所有都假定为字符串。除了主题和回复参数外,这些替换将应用于电子邮件正文的文本和html内容。每个personalization对象的替换总大小不能超过10000字节 所以这里没什么可做的 对于这种用法,Sendgrid还有另一个功能,称为节(也可以查看上面的链接)。它们的工作原理几乎类似于
替换
,只是它们链接到整个邮件,而不是每个替换
它们可以与替换一起使用
,以实现上述行为
正如mbernier在这里所说:
您可以这样使用它们:
"personalizations: [
{
"to: [{"email":"bob@example.com"}],
"substitutions": {
"[%product_info%]": "[%has_product%]",
},
},
{
"to":[{"email":"bob@example.com"}],
"substitutions": {
"[%product_info%]": "[%no_product%]",
},
}],
"content": [
{
"type": "text/plain",
"value": "We just wanted to tell you that we appreciate you being a long time customer! [%product info%]"
}],
"sections": {
"[%has_product%]": "Also, thanks for ordering:<br />[%product_section%].<br /> Are you ready to order again!?",
"[%no_product%]": "You haven't ordered in a while, but we'd love it if you came back and saw our new products!"
}
“个性化:[
{
收件人:[{“电子邮件”:bob@example.com"}],
“替换”:{
“[%product\U info%]”:“[%has\U product%]”,
},
},
{
“发送至”:[{“电子邮件”:”bob@example.com"}],
“替换”:{
“[%product\U info%]”:“[%no\U product%]”,
},
}],
“内容”:[
{
“类型”:“文本/普通”,
“价值”:“我们只是想告诉您,我们感谢您成为长期客户![%product info%]”
}],
“章节”:{
“[%has_product%]”:“另外,感谢您的订购:
[%product_section%]。
您准备好再次订购了吗!?”,
“[%no_product%]”:“您已经有一段时间没有订购了,但是如果您回来看看我们的新产品,我们会很高兴的!”
}
这里最重要的是,应该通过替换标记添加节
希望这有帮助