Passing js Variable to html file GAS - BASIC

后端 未结 2 606
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 04:30

I\'m trying to pass a variable (my name in cell A1) from my code.gs to my Index.html and email it.

Can someone please tell me what I\'m doing wrong or point me in th

2条回答
  •  耶瑟儿~
    2021-01-14 04:40

    The question was still open when I found it and I had a similar problem, so here is my solution (without doGet()), based on the useful comments from Wim den Herder and Rubén (and the example in the documentation):

    Code.gs

    function sendEmail() {
    var recipient = 'test@mail.de';
    var subject = 'Test Email'; 
    var message =     HtmlService.createTemplateFromFile('Index').evaluate().getContent();;
    
    
    // SEND THE EMAIL 
    GmailApp.sendEmail(
          recipient,         
          subject,                            
          message, {                        // body
          htmlBody: message                 // advanced options
        });
    
    }
    
    function getData(){
    var ss = SpreadsheetApp.openById('MySpreadSheetId');
    var sheet = ss.getSheetByName('Sheet1');
    // Data is in cell A1
    var myName = sheet.getRange(1,1).getValue();
    return myName
    }
    

    Index.html

    
    
      
      
      

提交回复
热议问题