【问题标题】:width: '100%' Symbol not working in Email Body - Postman宽度:“100%”符号在电子邮件正文中不起作用 - 邮递员
【发布时间】:2021-06-17 14:23:47
【问题描述】:

我正在尝试通过 NodeJS 发送带有 APIS 的电子邮件,这是我设计的带有 HTML 和 CSS 的电子邮件。

当我在 CSS 中使用 % 符号并触发电子邮件时,邮递员会返回错误 500。但如果我从代码中的每个位置删除 % 符号,它就可以正常工作。

身体的某些部位在sn-p下面是这样的

{
"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/

邮递员错误:

所以我想知道如何在正文中使用 '%' 或者我们是否需要转义/解析一些方法,任何提示或建议都会非常有帮助。谢谢你的时间:)

【问题讨论】:

  • 请添加邮递员截图
  • @PDHide,添加了 Postman 的截图 :)

标签: html css node.js postman email-client


【解决方案1】:

在 json 中,只允许使用双引号

所以吹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))

【讨论】:

  • 我也尝试过以下方式pastebin.com/MW6MrWuq,邮递员返回同样的错误。还是我在这里错过了什么?
  • 我的意思是服务器返回错误,而不是邮递员。但是,如果我删除 % 符号,它会起作用。
猜你喜欢
  • 1970-01-01
  • 2014-05-14
  • 2015-04-05
  • 1970-01-01
  • 2015-11-20
  • 1970-01-01
  • 1970-01-01
  • 2020-06-15
  • 2014-07-05
相关资源
最近更新 更多