调用HTML消息中的变量并为其着色

时间:2019-06-02 15:51:01

标签: html google-apps-script google-sheets

我正在寻求您的帮助:) 如何在“ var message”中调用所有变量并为其着色? 我现在使用常规字符串类型作为消息,但是我想使用具有更改字体大小和颜色的功能的HTML文本。我的代码结尾,您的文字有我的错误版本:)

预先感谢

function sendEmails() {
var sheet = 
SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var data = rows.getValues();
for (i in data) {
  var row = data[i];
  var currentShop = row[7] - 200000;
  var expectedShop = row[1] - 200000;

if(row[12] == "PL") {
  var Package = "Pilnie C&C-" + row[0];
} else {
    var Package = "Urgent C&C-" + row[0];
       }

var emailAddress = currentShop + "@gmail.com, " + expectedShop + "@gmail.com" ;

if(row[12] == "PL") {

  var message = "Drogi sklepie..... "

    } else {

      var message = "Hello shop " + currentShop + " (" + row[12] + ")," + '\n\n' + "according to the information in the system," + '\n' + "the parcel num. " + row[0] + '\n' + "was delivered to YOUR shop instead of to the correct one " + expectedShop + "(" + row[6] + ")." + '\n' + "Please check it and answer this e-mail. The parcel should be sent to the correct shop." + '\n' + "In case of any questions, please, contact me;

           }

MailApp.sendEmail(emailAddress, Package, message);
   }
};
<html>
<body>

Drogi sklepie <span style='color:red; '><strong><?= currentShop;?> ( <?=row[12];?> )</strong>,</span> <br><br>
wedle informacji z systemu, <br>
zamówienie <span style='color:orange; '><strong>nr <?=row[0];?></strong></span> <br> 
zamiast Waszego sklepu, powinno byæ przes³ane kurierem do sklepu <span style='color:green; '><strong><?=expectedShop;?> (<?=row[6];?>)</strong></span>. <br>
Proszê o sprawdzenie tego i odpowiedzenie na ten e-mail. <br>
W przypadku pytañ, proszê o kontakt ze mną

</body>
</html>

1 个答案:

答案 0 :(得分:1)

如果我对您的理解正确,那么您想要HTML格式的邮件正文,对不对?如果是这样,您应该在options调用中添加MailApp.sendEmail()参数(请参见MailApp reference for details),设置其htmlBody属性并编写HtmlString为此(或者,您可以通过HtmlService.createTemplateFromFile(yourFileName).evaluate()将其写入,因为您使用的是模板变量)