有没有办法从html电子邮件获取文本字段输入值

时间:2018-12-26 15:51:27

标签: javascript html email google-apps-script html.textboxfor

我目前正在使用Google脚本创建请假申请表。用户提交表单后,它将向主管发送电子邮件。主管可以批准或拒绝,并可以从电子邮件本身中说明拒绝的原因。我已经完成了所有工作流程并开始工作,现在我只能从电子邮件中输入的文本字段中检索值,并在电子表格中设置检索到的值。有任何建议或其他解决方法吗?

我尝试了document.getElementId(),但是这里没有定义文档,所以...我不太确定代码是否应该在doGet函数中,但是我认为它不太可能。

function sendingEmail(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Logger.log(sheet.getRange(25, 14).getValue());
var employeeName = e.values[1];
var email = e.values[2];
var email2 = e.values[3];
var supervisor = e.values[4];
var employeeNo = e.values[5];
var typeofLeave = e.values[6];
var leaveShift = e.values[8];
var otherReason = e.values[7];
var reason = e.values[9];
var dateFrom = e.values[10];
var dateTo = e.values[11];
var row = e.range.getRow();
var supervisoremail = sheet.getRange(row, 14);
var status = sheet.getRange(row, 13);
var rejectReason = sheet.getRange(row, 15);

var url = 'https://script.google.com/macros/s/******exec?';

var approve = url +'approval=true'+'&reply='+ email +'&reply2='+ email2 +'&row=' + row; 
var reject = url +'approval=false'+'&reply='+ email +'&reply2='+ email2 +'&row=' + row;

var html = "<body>"+
              "<h2>Please review the leave application</h2><br />"+
                "Employee Name :"+ employeeName + "<br />"+
                "Employee Email :" + email + "<br />"+
                "Employee Email opt :" + email2 + "<br />"+
                "Supervisor Name :" + supervisor + "<br />"+
                "Employee No :" + employeeNo + "<br />"+
                "Type of Leave :" + typeofLeave + "<br />"+
                "Leave Shift :" + leaveShift + "<br />"+
                "Other Reason for Leave :" + otherReason + "<br />"+
                "Reason :" + reason + "<br />"+
                "From :" + dateFrom + "<br />"+
                "To :" + dateTo + "<br />"+
                  "<a href="+approve +">Approve</a><br />"+
                    "<a href="+ reject +">Reject</a><br />"+
                    <p> //TEXT FIELD INPUT HERE
        <input type="text" value="" name="Email" placeholder="Reject  Reason" id="rejectreason"/> 
    </p>
         "</body>";
if (supervisor == 'Geralt'){
status.setValue('PENDING');
supervisoremail.setValue('GeraltofRivia@gmail.com.my'); //set supervisor emails  into spreadsheet
MailApp.sendEmail("GeraltofRivia@gmail.com.my", "Approval Request", "What no HTML?", {htmlBody: html}) 
var y = p.getElementById('rejectreason').value; //CODE ENTERS HERE?
rejectReason = setValue(y); //SETVALUE THE STRING INTO SPREADSHEET
}
else if (supervisor == 'Ciri'){
status.setValue('PENDING');
supervisoremail.setValue('Ciri@gmail.com'); //set supervisor emails into spreadsheet
MailApp.sendEmail("Ciri@gmail.com", "Approval Request", "What no HTML?",  {htmlBody: html}); /* ciri email here*/
}

电子邮件输出:
     请检查请假申请

Employee Name :Yennefer
Employee Email :
Employee Email opt :yenofvengerberg@gmail.com
Supervisor Name :
Employee No :yen T138
Type of Leave :Annual Leave
Leave Shift :Full day
Other Reason for Leave :
Reason :holiday
From :12/2/2018
To :12/3/2018
Approve
Reject
Reject reason (text field)

这是电子邮件html的外观。我希望在单击拒绝/批准链接后在电子表格中更新字符串或文本字段中的值。

1 个答案:

答案 0 :(得分:0)

简短的回答是“否”。电子邮件只能显示信息,而无法接收信息。 最好的选择是将链接放在电子邮件的正文中,当用户单击该链接时,它将用户重定向到页面,他可以在其中填写您要询问的字段