Apps Script sends old feedback page, but new feedback inside email - google-apps-script

I'm a beginner with Google app scirpts
i want send a feedback-page to users feedback typed into html form.
the script considers my changes into the email anwser.
but the feedback pages is always rendered with old form.html not the new antwortSeite.html.
should i use inside the forms also publish as webapp?
i do this with the Code.gs file.
i tried this but could not find any updates.
fileNameAntwortSeite = 'antwortSeite.html'; // <?= email ?>
var template = HtmlService.createTemplateFromFile(fileNameAntwortSeite);
template.email = 'huibuh#somebody.com';
antwortHtml = template.evaluate().getContent()
MailApp.sendEmail({to: kundenEmail, subject: 'test createTemplateFromFile'
, htmlBody: antwortHtml});
return antwortHtml;

Related

How to have Google Forms send automated email with new responses

I have a Google Form which I would like to automatically email someone when a new response is submitted. So far, I have just a simple HTML page with text in the body, however I would like the email content to include the form data as well.
Currently, this is what I have written:
function sendEmail(e) {
//response
var html = HtmlService.createTemplateFromFile("email.html");
var htmlText = html.evaluate().getContent();
var emailTo = "jeffreyabr#gmail.com"
var subject = "New SAP Role Request"
var textBody = "This email requires HTML support. Please make sure you open it with an email client that supports HTML"
var options = {htmlBody: htmlText};
GmailApp.sendEmail(emailTo, subject, textBody, options);
This came from following this basic YouTube tutorial.
Is there more Google Apps Script that I can add to accomplish this? Can I do this from Forms or must I do it from within Sheets?
The e.response object also contains the form data, which can be accessed by using e.response.getItemResponses().
Then to get the question, use getItem().getTitle(). To get the answer, use getResponse().
If you do not need the HTML response, then you can append the questions and answers to the textBody to display them on the email. Otherwise, you would have to add a script in your email.html using HTML scripts or google.script.run.
References:
Event Objects | onFormSubmit(e)
Class FormResponse

Filling Google Forms with Google Sheets

I have an HTML form which saves its responses to a Google Sheet. The form contains the following fields:
Name:
Email:
Subject:
Message:
Now, what I want is I want to automate sending a thank you email to a recipient as soon as he/she fills the form to the address mentioned in the "Email" field. I don't want to use Google Forms as the backend as it is hard to bypass the "Response Recorded" Confirmation page. Also, avoiding PHP would be better for me!
Is there a way to send these e-mails automatically? The format of the email is as follows:
From: <my email address>
To: <email address from the "Email" field in the spreadsheet>
Subject: Re: Submission Received
Hey <name from the "Name" field in the spreadsheet>!
Body of the mail
If there is a way to bypass the confirmation page of Google Forms, please let me know! That would also do!
If you have the data in google sheets, then you can handle your automation there. I setup this sample file that you could probably base your data set on.
From there I attached the below script to the spreadsheet. You would then need to set a trigger to execute this script on a somewhat regular frequency (5 minutes? 1 minute?). I think it should accomplish what you are going for. There's a check built in to ensure that partial data is not sent.
const ss = SpreadsheetApp.getActiveSheet();
const sentMessageColumn = ss.getRange("E:E").getColumn();
function regularProcedure(){
var aCell = ss.getRange(ss.getLastRow(),sentMessageColumn)
while(aCell.isBlank()){
var eRow = aCell.getRow();
if(!(ss.getRange(eRow,2).isBlank() ||
ss.getRange(eRow,3).isBlank() ||
ss.getRange(eRow,4).isBlank()))
{
var newMail = GmailApp.createDraft(
ss.getRange(eRow,2).getValue(),
ss.getRange(eRow,3).getValue(),
ss.getRange(eRow,4).getValue());
newMail.send();
aCell.setValue(true);
}
aCell=aCell.offset(-1,0);
}
}

Is it possible to email a form

I want to email a form to customers to fill out in the browser or ideally in rheir email client . I have created a form opened it by id , then sent it using
function openDialog() {
// Open a form by ID.
var form = FormApp.openById('kdhgsdfskfhs');
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();
MailApp.sendEmail({
to: 'me#gmail.com',
subject: 'hi',
htmlBody: htmlBody
});
}
You can see the result which I have put in screenshot . I'm starting to think that this is not doable in apps script. Is it possible ? if not what is the best way to send allow a user to enter info into a spreadsheet?
It's possible email html. But I think your going to need a website or a webapp or a link to the online form to submit it to a spreadsheet.

How to persist Google Apps HtmlObject created with template.evaluate() to a URL?

I am using a Google Spreadsheet and its triggered App Script to compose and send daily status information in an html-formatted email. The email message body is composed using an html template into which token data are inserted from spreadsheet data and calculations. After insertion, the HtmlObject becomes the body of the email message using code like the following:
htmlBody = template.evaluate();
MailApp.sendEmail({
to: emailRecipients,
replyTo: emailReply,
subject: 'Today's Management Report',
htmlBody: htmlBody.getContent(),
});
I would also like to post the daily HtmlObject (Management Report) on our website but I cannot find a method to persist the object to a URL. Can anyone provide some guidance how to do this?
Thanks.
I will add to Jack Brown's comment above about deploying the HtmlObject as a Web app. Once you have deployed the HTML, you can get the URL with the ScriptApp service. The documentation provides an example close to what I think you are looking for: https://developers.google.com/apps-script/reference/script/service#getUrl()
// Mail the URL of the published web app.
MailApp.sendMail("myself#example.com", "My Snazzy App",
"My new app is now available at " + ScriptApp.getService().getUrl());
In case it helps others, here is the gs code I used to persist the blob and move it from Drive's root folder to its target destination folder:
// create pdf version of daily report
var title = "Daily Operations Summary - " + Utilities.formatDate(currStatusDate,'MST','MM/dd/yyyy') + ".pdf";
var htmlDaily = htmlBody.getContent();
var blob = Utilities.newBlob(htmlDaily, 'text/html').getAs('application/pdf').setName(title);
// save file and move to target folder
var fileID = DriveApp.createFile(blob).getId();
var destfolderID = "your Google folder GUID";
var file = DriveApp.getFileById(fileID);
file.getParents().next().removeFile(file);
DriveApp.getFolderById(destfolderID).addFile(file);

Google Apps Script — Automatically Email and Share

I am attempting to write a small Google Apps script that will send a confirmation email and automatically share a folder with a logged-in user after they complete a form. Here is the script:
function formSubmitReply(e) {
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: "Keuka College Brand Download Center",
htmlBody:
"<p>Thank you for requesting access to the Keuka College Brand Download Center. Your access has been approved.</p>" +
"<p>You may access the download center by <a href='https://drive.google.com/a/keuka.edu/folderview?id=0B856ZeGoaGT_MG5BMEtEVGwzYkk&usp=sharing'>using this link,</a> " +
"visiting <a href='http://brand.keuka.edu'>Keuka College Brand Central,</a> or through your Google Drive.</p><p>Please contact the Office of Marketing and Communications " +
"with any questions you may have.</p>",
name: "Keuka College",
replyTo: "marketing#keuka.edu"
});
var folder = DocsList.getFolder('Brand Download Center');
folder.addViewer(Session.getActiveUser());
}​
This seems to be working, except it keeps emailing it to me -- not the user who is completing the form. I am not sure if it is sharing correctly.
Could someone provide some insight? This is my first time working with Google Apps script.
Session.getActiveUser() is the user that uses the form editor and the user that created the trigger that calls this function.
What you want us the user that filled the form.
Look at the documentation here to see how you can retrieve that value. Note that it will only be available if you are in a domain.
EDIT (sorry for the delay)
Here is a sample code to show how to get the form respondent in formApp (works only in GAFE or GA Business)
It will send you a mail with the name of the last form submitter (don't forget to create an installable onEdit trigger to test this).
function onSubmit(){
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
var lastResponse = formResponses[formResponses.length-1];
var user = lastResponse.getRespondentEmail()
var userString = 'user = '+user;
MailApp.sendEmail(Session.getActiveUser().getEmail(),'form submission report',userString);
}