【问题标题】:Change GMail text color in the middle of a line更改一行中间的 GMail 文本颜色
【发布时间】:2015-10-20 12:59:40
【问题描述】:

我正在尝试使用现有的 Google 脚本,并且我想更改脚本生成的电子邮件中句子中某些单词的颜色。在下文中,我希望“落后”为红色。我试过字体标签,但它们不起作用。有什么建议吗?

  if (firstItem) {
    body = "This is an email to inform you of course progress.\n\n" + studentName + " is <font color="red"> behind pace </font> in the following subjects:\n";  
    firstItem = false;
  } else { 
    body += "\n";  
  }

【问题讨论】:

  • 你托盘&lt;span&gt;标签了吗? &lt;span style="color:#FF0000"&gt;word&lt;/span&gt; ?
  • 显示所有相关代码并显示你尝试过的和没有工作的。
  • 上面的编辑版本。我尝试用 标签替换字体标签,但无法运行。

标签: html css google-apps-script inline-styles


【解决方案1】:

&lt;span&gt; 标签正是您要寻找的; HTML (anymore...) 中没有 &lt;font&gt; 标签。该标签接受 style 属性,该属性使用 CSS 来描述 span 内容的外观。 (进一步了解 CSS here。)

  if (firstItem) {
    body = "This is an email to inform you of course progress.\n\n"
         + studentName
         + " is <span style='color:red;'>behind pace</span> in the following subjects:\n";  
    firstItem = false;
  } else { 
    body += "\n";  
  }

注意事项:

  • 您必须使用htmlBody 选项发送此电子邮件。

    GmailApp.sendEmail(recipient, subject, '', {htmlBody:body});
    
  • Gmail 是众多仅支持嵌入式样式的电子邮件客户端之一。见How do I use Google Apps Script to change a CSS page to one with inline styles?

  • 在字符串中嵌入字符串时要小心使用引号。在 JavaScript 中,您需要将单引号 (') 和双引号 (") 配对,但您可以将一个嵌套在另一个中,或者转义内部引号 ("string \"internal string\" end of string")

【讨论】:

  • 感谢您的帮助,但我仍然无法使其正常工作。我尝试了 Mogsdad 建议的代码,电子邮件包含以下文字:“Ima Nutherstoodunt 在以下主题中落后:”我绝对是个新手,而且我'我正在编辑别人的脚本,我无法完全解释。
  • 您阅读我添加的“注释”了吗?在我看来,当它需要是 htmlBody 时,您只是将电子邮件正文作为文本发送。
猜你喜欢
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-08
相关资源
最近更新 更多