I sent a mail via google script which sends button in email body, I want to update a spreadsheet when button in email body is clicked.I am unable to trigger the function present in script.
myfunction1 is used to send the email with button in body.
function myfunction1() {
var htmlBody = HtmlService.createHtmlOutputFromFile('mail_template').getContent();
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: 'Testing Gmail action:',
htmlBody: htmlBody,});}
body in mail_template
<html>
<body>
<p id="demo"></p>
<div>EMAIL CONTENT GOES HERE<br/></div>
<form>
<input type="button" id='mybtn' onclick="google.script.host.updatesheet()" value ="click me"/>
</form>
</body>
</html>
updatesheet is the function used to update the spreadsheet.
function updatesheet()
{
var spreadsheetkey = "1q2hgrZZCR1ytQEX-irUQWjXg5g6YNaRwcfsTQq7UZ30";
var sheet = SpreadsheetApp.openById(spreadsheetkey).getActiveSheet();
var lastrow = sheet.getLastRow();
sheet.getRange(lastrow+1, 1).setValue("testing");
}