Google App脚本 - 从邮件正文回拨 [英] Google App Script - callback from Mail body
问题描述
我发送一个包含按钮的邮件正文中的html表单,当点击按钮时,我在google电子表格中保存了一个参考。
// //函数从Google App脚本发送邮件
function sendmail(e){
var subject ='Test';
var template = HtmlService.createHtmlOutput('< form id =myForm>'+
'< label for =name>名称:< / label> '+
'< input type =textid =name/>'+
'< / Form>'+
'< button onclick =submitdata )> Save< / button>'+
'< script>'+
'function submitdata(){'+
'var form = document.getElementByID('+myform '+');'+
'google.script.run.withFailureHandler(alert).withSuccessHandler(alert)。'+
'submitForm(form);'+
'}') ;
var html = template.getContent();
//电子邮件给自己
recipient = Session.getActiveUser()。getEmail();
var Mailbody ='它是一个测试:'
//发送电子邮件形式
GmailApp.sendEmail(收件人,主题,Mailbody,{htmlBody:html});
}
//单击电子邮件正文中的保存按钮时调用的函数
函数submitForm(form){
var ss = SpreadsheetApp.openById('tsgxsbtJRf2zbh_tNQzJoUQ');
var sheet = ss.getSheets()[0];
//保存对电子表格的响应
var rowNum = sheet.getLastRow()+ 1;
//sheet.getRange (rowNum,1,1,row.length).setValues([row]);
sheet.getRange(A+ rowNum).setValue(today)
}
对于某些客户来说,有什么作用是让表单带有一个普通的发布网址,这样当用户填写字段并点击提交按钮时,它会在他们的浏览器上发布一个新的标签,发布表单直。但是,再次,这只适用于某些电子邮件客户端。例如,我不认为这适用于Outlook。
在这种情况下,您可以做的最好做法是发送链接,以便用户可以在线打开我们的表单。
I am sending an html form in body of the mail with a button included and when button is clicked i am saving a reference in google spreadsheet. I was able to get the code and not able to get it worked.please help me in fixing the issue.
//Function to send mail from Google App script
function sendmail(e) {
var subject = 'Test';
var template = HtmlService.createHtmlOutput('<form id = "myForm" >' +
'<label for = "name"> Name: </label>'+
'<input type = "text" id ="name" />'+
'</Form>'+
'<button onclick = "submitdata()">Save</button>' +
'<script>' +
'function submitdata(){'+
'var form = document.getElementByID('+"myform"+');'+
'google.script.run.withFailureHandler(alert).withSuccessHandler(alert).' +
'submitForm(form);'+
'}');
var html = template.getContent();
// email to self
recipient = Session.getActiveUser().getEmail();
var Mailbody= 'Its a test: '
// Send email form
GmailApp.sendEmail(recipient, subject, Mailbody, {htmlBody:html} );
}
//Function to be called when clicked on Save button in Email body
function submitForm(form) {
var ss =SpreadsheetApp.openById('tsgxsbtJRf2zbh_tNQzJoUQ');
var sheet = ss.getSheets()[0];
// Save response to spreadsheet
var rowNum = sheet.getLastRow()+1;
//sheet.getRange(rowNum, 1, 1, row.length).setValues([row]);
sheet.getRange("A"+ rowNum).setValue("today" )
}
No email client that I know of, traditional (e.g. outlook) or online (e.g. gmail) will run javascript code embedded in html.
What work on some clients is to have the form with a regular post URL, so that when the user fill the fields and click the submit button, it'll trigger a new tab on their browser posting the form directly. But then again, this only work on some email clients. For example, I don't think this works on Outlook.
In such cases, the best you can do is to send a link so the user can open our form online.
这篇关于Google App脚本 - 从邮件正文回拨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!