我正在尝试通过NodeJS发送一封带有APIS的电子邮件,这是我设计的一封带有超文本标记语言和CSS的电子邮件。
当我在CSS中使用%
符号,并触发一封电子邮件时,邮递员返回错误500。但是如果我从代码中的任何地方删除%
符号,它都可以正常工作。
身体的某些部分看起来像下面的代码片段
{
"toAddress" : "author.details@example.com",
"subject" : "Test - Mail Server",
"body" : '<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding-right: 0px;padding-left: 0px;" align="center">
<img align="center" border="0" src="https://www.google.com/images/srpr/logo3w.png" alt="Image" title="Image" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 580px;" width="580"/>
</td>
</tr>
</table>',
"fromAddress" : "example@example.com"
}
完整的代码在这里:https://jsfiddle.net/f2vr40bu/
邮递员错误:
所以我想知道如何在正文中使用'%‘,或者我们是否需要转义/解析一些方法,任何提示或建议都会很有帮助。感谢您的宝贵时间:)
发布于 2021-06-17 14:23:47
在json中,只允许使用双引号。
所以blow json是无效的:
{
"toAddress" : "author.details@example.com",
"subject" : "Test - Mail Server",
"body" : '<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding-right: 0px;padding-left: 0px;" align="center">
<img align="center" border="0" src="https://www.google.com/images/srpr/logo3w.png" alt="Image" title="Image" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 580px;" width="580"/>
</td>
</tr>
</table>',
"fromAddress" : "example@example.com"
}
您必须转义双引号并将下一行替换为\n。更好的方法是
{
"toAddress" : "author.details@example.com",
"subject" : "Test - Mail Server",
"body" : "{{body}}",
"fromAddress" : "example@example.com"
}
并在请求前使用
let body = `<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="padding-right: 0px;padding-left: 0px;" align="center">
<img align="center" border="0" src="https://www.google.com/images/srpr/logo3w.png" alt="Image" title="Image" style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 580px;" width="580"/>
</td>
</tr>
</table>`
pm.environment.set("body",JSON.stringify(body))
https://stackoverflow.com/questions/67999341
复制相似问题