首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >宽度:'100%‘符号在电子邮件正文中不起作用-邮递员

宽度:'100%‘符号在电子邮件正文中不起作用-邮递员
EN

Stack Overflow用户
提问于 2021-06-16 16:50:34
回答 1查看 78关注 0票数 1

我正在尝试通过NodeJS发送一封带有APIS的电子邮件,这是我设计的一封带有超文本标记语言和CSS的电子邮件。

当我在CSS中使用%符号,并触发一封电子邮件时,邮递员返回错误500。但是如果我从代码中的任何地方删除%符号,它都可以正常工作。

身体的某些部分看起来像下面的代码片段

代码语言:javascript
运行
复制
{
"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/

邮递员错误:

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

EN

Stack Overflow用户

发布于 2021-06-17 14:23:47

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

所以blow json是无效的:

代码语言:javascript
运行
复制
{
"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。更好的方法是

代码语言:javascript
运行
复制
 {
"toAddress" : "author.details@example.com",
"subject"   : "Test - Mail Server",
"body"      : "{{body}}",
"fromAddress" : "example@example.com"
}

并在请求前使用

代码语言:javascript
运行
复制
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))
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67999341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档