电子邮件内容显示在电子邮件预览中但不显示在邮件本身中 - Google Apps Script MailApp

Email content showing in email preview but not in message itself - Google Apps Script MailApp

我正在尝试制作一个脚本,通过电子邮件从 Google 表格发送 table。我将内容传递给 HTML 文件,然后毫无问题地从 HTML 文件中取回它。 (HTML table 代码显示在控制台日志中。)MailApp 似乎 运行 正常。当我查看我的电子邮件时,一切看起来都正确(甚至预览),但电子邮件本身没有显示任何内容...

谁能给我解释一下这是怎么回事?

这是我的代码。请原谅我的笔记,它们是为知识比我还少的人准备的。

  console.log("");                                      // The console log runs parallel to execution, for debugging. This is just a spacer, it makes the console log easier to read. 
  console.log("");
  console.log("// BEGIN EXECUTION //");                 // This is also a console log, it tells me that the script started running. 
  
  var ss=SpreadsheetApp.getActive();                    // This script is "bound" to the spreadsheet, but we still need to tell the script what spreadsheet we're talking about
  var sheet=ss.getSheetByName("Automated WeeklyScheduleToVolunteers"); // This directs the script to the right "tab" in the spreadsheet. This also means if you rename the tab, the script stops working. 
  
  console.log("Spreadsheet identified");                // See above, I'll stop commenting on the "just a notification"-type logs.
  
  var target_date = sheet.getRange("G2").getDisplayValue(); // This gets the G2 value, which the spreadsheet produces for the next service. 
  var lr = sheet.getLastRow();                          // This finds the last row of the sheet with data in it.
  var tableRangeValues = sheet.getRange(5,4,lr - 4,4).getDisplayValues(); // This gets the values from D5 to the last row (minus 4, so we skip the header), and four columns (the whole table).
  var htmlTemplate = HtmlService.createTemplateFromFile("Email"); // This tells the script we're going to use the file Email.html (which calls variables from this script)
  htmlTemplate.tableRangeValues = tableRangeValues;     // This "passes" the values from the script to the HTML template. 

  console.log("Content passed to HTML");

  var htmlForEmail = htmlTemplate.evaluate().getContent(); // This "passes" the values back from the HTML template. 

  console.log("Content passed back from HTML");
  console.log("htmlForEmail = " + htmlForEmail);        // This logs the content of the htmlForEmail variable. 


// NOTE TO ADAM: MAKE THIS SECTION DYNAMIC


  var volunteer_emails=sheet.getRange(2,2,44,1).getDisplayValues(); // this gets the values from B2:B45 (the email addresses)

  console.log("Emails fetched");
  console.log("volunteer_emails are " + volunteer_emails);
  
  var sent_value = sheet.getRange("G4").getDisplayValue(); // This sees whether this week's email has been sent or not

/* 

This next section is a little intimidating. But, it's just using a IF-THEN-ELSE logic. If something is true, do X action. If it's not true (the "else") do Y action. 

*/


  if (sent_value === "Email_Sent"){                     // If the email HAS ALREADY been sent...
     var ui = SpreadsheetApp.getUi();                   // (Open the user interface)
     var result = ui.alert(                             // ... send an alert,
      "ERROR: Weekly Schedule for " + target_date + " is already marked 'Sent.'", // ... with this text,
      "Are you sure you would like to send it again?",
       ui.ButtonSet.YES_NO);                            // ... and a "Yes" "No" option. 

     if (result == ui.Button.YES) {                     // If the user clicks "Yes"...
        MailApp.sendEmail({to: volunteer_emails.toString(),subject: target_date + ' - CPP Team Schedule',htmlBody: htmlForEmail}); //... send the email and
        });



       ui.alert("SUCCESS: Weekly Schedule for " + target_date + " has been sent.");    // ... send a confirmation alert.
     } else {                                           // If the user clicks "No"...
       ui.alert('NOTE: No reminder was sent.');                // ... send a cancellation alert.
     }                                                  // This closes the if-else statement

  } else {                                              // If the email HAS NOT YET been sent...
     MailApp.sendEmail({to: volunteer_emails.toString(),subject: target_date + ' - CPP Team Schedule',htmlBody: htmlForEmail}); //... send the email and
     var ui = SpreadsheetApp.getUi();                   // (Open the user interface)
     ui.alert("SUCCESS: Weekly Schedule for " + target_date + " has been sent."); // ... give a notification to the user, and
     var rng = SpreadsheetApp.getActive().getSheetByName("Sunday Team Schedule Current").getRange("A3:4"); // (This gets the first two lines for the Sunday Team Schedule Current.)
     var vs = rng.getDisplayValues();                   // (This gets the values from the range.)
     for (var j = 0; j < rng.getLastColumn(); j++) {    // (This searches the range for the target date)
       if (vs[0][j] == target_date) {                   // ... if a column = target_date, then... 
           SpreadsheetApp.getActive().getSheetByName("Sunday Team Schedule Current").getRange(4,1+j).setValue("Email_Sent"); // ... put "Email_Sent" in that column, "correcting" for the zero index. 
       }                                                // This closes the if.
     }                                                  // This closes the for.
  }                                                     // This closes the if (email sent)-else.
}                                                       // This closes the function.
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>


    <div>

      <div style="height:4px">
        <table>
          <tbody>
              <? tableRangeValues.forEach(r => { ?> 
                <tr>
                  <td><?= r[0] ?></td><td><?= r[1] ?></td><td><?= r[2] ?></td><td><?= r[3] ?></td>
                </tr>
              <? }) ?>
          </tbody>
        </table>
      </div>

    </div>


  </body>
</html>

问题出在您的 HTML 文件的 <div style="height:4px"> 中。内容高度大于 div 容器高度。将其更改为更大的值或删除高度属性将解决此问题。

示例:

<div style="height:4px">:

<div style="height:40px">:

没有高度属性: