使用 firebase 并使用模板发送电子邮件时,是否可以将 html 放入数据字段并进行渲染?
我正在尝试使用 Firebase 提供的扩展程序通过 Firebase 发送电子邮件,并且我正在使用模板。模板有一个html主体,我传入了几个数据参数。
在两种情况下,我想从数据字段中渲染 html。我注意到两个问题:在某些情况下,html 未呈现(注意:只有数据字段中的 html 未呈现,模板中的 html 工作得很好),而在其他情况下,它完全阻止了消息从被发送。
当我添加标签时,如在
inviteMessage
字段中,该标签不会由电子邮件呈现:
(注意:这些屏幕截图来自两个不同的测试,但您可以看到标签显示为原始字符串而不是渲染 html。)
在一个单独的字段中,我尝试呈现表格的整个部分(因为整个表格单元格取决于传递到消息中的数据)。但是将其添加到数据字段完全阻止消息发送:
<!-- Member Info Content -->
<td style="flex: 0 0 auto; display: flex; align-items: flex-start; flex-direction: column; justify-content: center;"
class="details-member-info">
<tr>
<td><h2 style="font-family: 'Inter', sans-serif;">Members</h2></td>
</tr>
<tr>
<td style="text-align: left; padding-left: 48px;">
<ul style="position: relative; padding-inline-start: 0px;">
<li style="height: 48px; list-style-type: none; padding: 8px;" class="member-li list-item">
<img alt="image"
src="https://firebasestorage.googleapis.com/v0/b/iron-accountability.appspot.com/o/userImages%2FoXC9rWMsUDezvKe0Vu09ON1NMc42%2FprofileImage.jpg?alt=media&token=992e6a97-3755-463b-afab-87b89cc9f7a2"
style="width: 48px; height: 48px; display: inline-block; vertical-align: middle; object-fit: cover; border-radius: 50%; border: 2px solid #000000;"
class="member-image" />
<span style="vertical-align: middle; display: inline-block; padding-left: 8px; font-size: 16px; font-weight: 700; font-family: 'Inter', sans-serif;"
class="member-li-name">Charlie Page</span>
</li>
<li style="height: 48px; list-style-type: none; padding: 8px;" class="member-li list-item">
<img alt="image" src="https://www.lattisapp.com/images/blank-avatar.jpg"
style="width: 48px; height: 48px; display: inline-block; vertical-align: middle; object-fit: cover; border-radius: 50%; border: 2px solid #000000;"
class="member-image" />
<span style="vertical-align: middle; display: inline-block; padding-left: 8px; font-size: 16px; font-weight: 700; font-family: 'Inter', sans-serif;"
class="member-li-name">Charlie Page</span>
</li>
</ul>
</td>
</tr>
</td>
你可以看看这个,它是关于如何在 Flutter(Dart) 中将 String 转换为 HTML 编码的字符串。
const HtmlEscape htmlEscape = HtmlEscape();
String unescaped = 'Text & subject'; // Data you fetched from Firebase store datafields
String escaped = htmlEscape.convert(unescaped);
print(escaped); // Text & subject
unescaped = '10 > 1 and 1 < 10'; // Data you fetched from Firebase store datafields
escaped = htmlEscape.convert(unescaped);
print(escaped); // 10 > 1 and 1 < 10
unescaped = "Single-quoted: 'text'"; // Data you fetched from Firebase store datafields
escaped = htmlEscape.convert(unescaped);
print(escaped); // Single-quoted: 'text'
unescaped = 'Double-quoted: "text"'; // Data you fetched from Firebase store datafields
escaped = htmlEscape.convert(unescaped);
print(escaped); // Double-quoted: "text"
unescaped = 'Path: /system/'; // Data you fetched from Firebase store datafields
escaped = htmlEscape.convert(unescaped);
print(escaped); // Path: /system/
https://api.flutter.dev/flutter/dart-convert/HtmlEscape-class.html