/** Replace the "<DOCID>" with your document ID, or the entire URL per say. Should be something like: var EMAIL_TEMPLATE_DOC_URL = 'https://docs.google.com/document/d/asdasdakvJZasdasd3nR8kmbiphqlykM-zxcrasdasdad/edit?usp=sharing';*/varEMAIL_TEMPLATE_DOC_URL='https://docs.google.com/document/d/<DOCID>/edit?usp=sharing';varEMAIL_SUBJECT='This is an important email';/** * Sends a customized email for every response on a form. * * @param {Object} e - Form submit event */functiononFormSubmit(e){varresponses=e.namedValues;// If the question title is a label, it can be accessed as an object field.// If it has spaces or other characters, it can be accessed as a dictionary./** NOTE: One common issue people are facing is an error that says 'TypeError: Cannont read properties of undefined' That usually means that your heading cell in the Google Sheet is something else than exactly 'Email address'. The code is Case-Sesnsitive so this HAS TO BE exactly the same on line 25 and your Google Sheet. */varemail=responses['Email Address'][0].trim();Logger.log('; responses='+JSON.stringify(responses));MailApp.sendEmail({to:email,subject:EMAIL_SUBJECT,htmlBody:createEmailBody(),});Logger.log('email sent to: '+email);// Append the status on the spreadsheet to the responses' row.varsheet=SpreadsheetApp.getActiveSheet();varrow=sheet.getActiveRange().getRow();varcolumn=e.values.length+1;sheet.getRange(row,column).setValue('Email Sent');}/** * Creates email body and includes the links based on topic. * * @param {string} name - The recipient's name. * @param {string[]} topics - List of topics to include in the email body. * @return {string} - The email body as an HTML string. */functioncreateEmailBody(){// Make sure to update the emailTemplateDocId at the top.vardocId=DocumentApp.openByUrl(EMAIL_TEMPLATE_DOC_URL).getId();varemailBody=docToHtml(docId);returnemailBody;}/** * Downloads a Google Doc as an HTML string. * * @param {string} docId - The ID of a Google Doc to fetch content from. * @return {string} The Google Doc rendered as an HTML string. */functiondocToHtml(docId){// Downloads a Google Doc as an HTML string.varurl='https://docs.google.com/feeds/download/documents/export/Export?id='+docId+'&exportFormat=html';varparam={method:'get',headers:{'Authorization':'Bearer '+ScriptApp.getOAuthToken()},muteHttpExceptions:true,};returnUrlFetchApp.fetch(url,param).getContentText();}