Moses
Moses

Reputation: 236

Send report to mail in Google Sheets

I have some product list with agent mail ID, Daily basis I need to send report to the concern agents from Spreadsheet enter image description here

Here is the report

    function myFunction() {
    {
    var emailTemp = HtmlService.createTemplateFromFile("responsing");
      var ws= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Request");
      var data = ws.getRange(1,1,1,ws.getLastColumn()).getValues();

  data.forEach(function(row){
      var htmlMessage=emailTemp.evaluate().getContent();
      GmailApp.sendEmail(
        row[mail],
       "Report",
        "Your browser doesn't support HTML",
       {name:"VUC-GISOCC",htmlBody:htmlMessage,cc: 'agent' }
      );
    
      });
    
    }

I am using the above script, but don't know how to send content to the concern agent in cc. Example

Agent [email protected] should get Orange detail
Agent [email protected] should get Apple detail
Agent [email protected] should get Grape detail

FYI, I am using HTML body, that's why I added htmlMessage It's getting only [email protected] as I put 1 in var data = ws.getRange(1,1,1,ws.getLastColumn()).getValues();

Upvotes: 0

Views: 72

Answers (1)

Cooper
Cooper

Reputation: 64072

Change this ws.getRange(1,1,1,ws.getLastColumn()).getValues(); to this ws.getRange(2,1,ws.getLastRow()-1,ws.getLastColumn()).getValues();

if you have other stuff below the table table then you may wish to use ws.getRange(2,1,3,ws.getLastColumn()).getValues(); if you data doesn't change but if it does you will be forced to change the third parameter which is the number of rows in the range.

Upvotes: 1

Related Questions