背景:
我有一个 NodeJS 应用程序保存着我的 Cognito 用户池的 Lambda 触发器处理程序。该应用程序有多个 NodeJS 客户端应用程序。我的每个客户端应用程序都有多个
ForgetPassword
html 模板(用于电子邮件)。
问题:
我在客户端应用程序中遇到
CustomMessage
Lambda for ForgetPassword
触发器问题,出现以下错误(从我的邮递员复制/粘贴):
at 'emailBody' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}\\s*]*\\{####\\}[\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}\\s*]*
AWS 文档(此处)中提到,
emailMessage
必须包含:{####}
。对于我的电子邮件模板,我确实包含了这一点。但奇怪的是,客户端应用程序 1 工作正常(发送了正确的模板,并且 {####}
被 Cognito 生成的代码替换),但客户端应用程序 2 却不能(它抛出上面显示的错误)。
我还希望您强调这一点:在错误中,据说模板不遵守应该验证模板是否具有
{####}
的正则表达式,但错误的正则表达式确实检查 \{####\}
。这是为什么?正则表达式应该是 {. . .}*\{####\}{. . .}
而不是 {. . .}*\\{####\\}{. . .}
。
代码:
CustomMessage ForgotPassword 触发器处理程序:
module.exports.customMessageHandler = async (event, context, callback) => {
// LOGIC IN HERE . . .
if (event.triggerSource === "CustomMessage_ForgotPassword") {
if (//check which app is it: app 1 or app 2 to choose the correct template) {
let message = async readFile(path_to_right_template);
event.response.emailMessage = message;
event.response.emailSubject = 'Forgot password recovery';
console.log(message). // I log the html template to make sure that it holds the {####}, and it does!
}
}
callback(null, event);
}
电子邮件 HTML 模板
<div> . . . content </div>
<table border="0" cellpadding="0" cellspacing="0" class="html_block"
role="presentation"
style="mso-table-lspace: 0pt; mso-table-rspace: 0pt;"
width="100%">
<tr>
<td>
<div align="center"
style="font-family:Ubuntu, Tahoma, Verdana, Segoe, sans-serif;text-align:center;">
<div class="our-class"
style="margin:0 auto; height:40px; width:120px; background-color:#c2daf2; padding-top:10px;border-radius: 10px;">
{####}
</div>
</div>
</td>
</tr>
</table>
<div>content . . .</div>
感谢大家的帮助,如果我遗漏了任何可以帮助调试此问题的信息,请告诉我。
我们遇到了这个问题,特别是在
CustomMessage_ForgotPassword
模板中(尽管所有模板中都出现了同样的问题);并发现这是由于可疑的、不可打印的字节被输出到模板中造成的。
重复的 U+200E 和 U+200F(LTR 和 RTL),我们追踪到 React-Emails 中的这段代码:https://github.com/resend/react-email/blob/canary/packages/预览/src/preview.tsx#L38
我们使用 HTML 实体重新实现了
Preview
组件。以下是其他一些解决方案:https://github.com/resend/react-email/issues/609#issuecomment-1544306378