1
votes

I have a google sheet with Student Name, Roll no, Marks in Physics, Chemistry, Maths & practical for around 80 students. Every day we do test and the marks I have to send to head office by evening. Only the students got more than 40 marks in physics & chemistry and above 50 in Maths.

I have prepared Gmail.sendEmail and this working fine but sending separate email for each row. What I require is ending single email with break for each student. I am furnishing the script code as well as the html code.

function sendEmail() {

  var temp = HtmlService.createTemplateFromFile('xxx')

  var sub = "STUDENT MARKS";
  var email = "[email protected]";
  var name = "Branch Office";

  for (i in data) {
      row =   data[i];
      temp.name =   row[0];
      temp.roll =   row[1];
      temp.phy =    row[2];
      temp.chem =   row[3];
      temp.math =   row[4];
      temp.pract =  row[5];

      if(temp.phy => 40 && temp.chem => 40 && temp.math => 50){
          var htmlMessage = temp.evaluate().getContent();

          GmailApp.sendEmail(email, sub,"not supported",{
                   name: name,htmlBody: htmlMessage,
          });
       } 
    }   
} 

html code

<p>  
<b>Student Marks </b>
<br><br>
Student Name:<?= rgp  ?> Roll no:<?= rgpdt  ?><br>
Marks in Physics: <?= phy  ?><br>
Marks in Chemistry: <?= chem  ?><br>
Marks in Maths: <?= math  ?><br>
Marks in Practical:<?= pract  ?>
</p>
1

1 Answers

1
votes

Try this:

function sendEmail() {
  var html="";
  var sub = "STUDENT MARKS";
  var email = "[email protected]";
  var name = "Branch Offioce";
  for (var i=0;i<data.length;i++) {
    row =   data[i];
    temp.name =   row[0];
    temp.roll =   row[1];
    temp.phy =    row[2];
    temp.chem =   row[3];
    temp.math =   row[4];
    temp.pract =  row[5];
    if(temp.phy => 40 && temp.chem => 40 && temp.math => 50){var html+=temp.evaluate().getContent()+'<br />';} 
  }
  if(html) {
    GmailApp.sendEmail(email, sub,"",{name: name,htmlBody:html});
  }
}