GMail html 正文是否可以在 GAS 中使用 Materialize、Bootstrap 等进行格式化?

Can GMail html body be formatted with Materialize, Bootstrap etc. in GAS?

在使用 GMailApp.sendEmail 方法从 Google Apps 脚本发送带有 html 正文的电子邮件时,可以预先设置 html 的样式。但是,当尝试使用 Materialize 进行样式设置时,它对我来说失败了,并且邮件显示为基本未格式化 html。我知道 html 模板很挑剔,但是否可以应用样式框架?如果是这样,有谁知道如何调试导致它失败的原因?

示例 GA 脚本 (code.gs):

function spamMe() {
  let recipient = 'mymail@gmail.com';
  let subject = 'Your daily serving of spam. For FREE!';
  let html = HtmlService
    .createTemplateFromFile('emailbody')
    .evaluate()
    .getContent();
  GmailApp.sendEmail(recipient, subject, '', { htmlBody: html });
}

示例 html 正文模板 (emailbody.html):

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
  </head>
  <body>    
    <div class="container">
      <h1>Hey worldo!</h1>
      <div class="row">
        <div class="col s12 m5">
          <div class="card-panel teal">
            <span class="white-text">I am a very simple card. I am good at containing small bits of information.
            I am convenient because I require little markup to use effectively. I am similar to what is called a panel in other frameworks.
            </span>
          </div>
        </div>
      </div>
    </div>    
    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
  </body>
</html>

理论上它 可以 工作,只要您内联代码(style="..." 而不是 <link>)。不过,这是一个非常大的“可能”,因为像 Bootstrap、Materialise 这样的大多数系统都是为网络构建的,其功能与电子邮件完全不同。

因此,大多数(所有?)系统都依赖 <div>s,而 Outlook 桌面不能很好地与 <div>s 配合使用,这对您来说效果不佳。

深入挖掘,使用两列和三列,您也可以对它们进行不同的设置,这样即使没有媒体查询它们也可以堆叠。

此外,许多组件的编码方式不同,并且不使用 Bootstrap 所依赖的 flexbox 等。请参阅 https://www.caniemail.com/ 了解详细信息。

但是,有一个名为 MJML (https://mjml.io/) 的系统可以满足您的需求。但它是编译的,而不是 class 驱动的。