Is it possible to email a form - google-apps-script

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.

Related

How do I send an autoreply few minutes after the trigger in Google Apps Script?

I have a Google Apps Script code like this where I am sending an autoreply email upon submission of a Google Form. This will send an email immediately after the form submission but is there a way to send this autoreply 5 minutes after the form is submitted in Google Form?
function autoReply(e) {
var values = e.values;
...
var email = value3;
var title = "EMAIL TITLE COMES HERE";
var body = `
DEAR CUSTOMER,
EMAIL BODY COMES HERE
`;
GmailApp.sendEmail(email, title, "", {
htmlBody: body
});
You can use Utilities.sleep, its max allowed value is 5 minutes/300000 milliseconds
Use this method before the lines which take care of the sending part of operation.
Reference
Utilities.sleep

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);
}
}

Apps Script sends old feedback page, but new feedback inside email

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;

Google Apps Script - inline images example doesn't work

I'm trying to get this example script working from this Google Developer page.
I put the below code, which is copy/pasted verbatim (except for the "recipient#example.com" of course) into a function which runs when a form is submitted.
// This code fetches the Google and YouTube logos, inlines them in an email
// and sends the email
function inlineImage() {
var googleLogoUrl = "http://www.google.com/intl/en_com/images/srpr/logo3w.png";
var youtubeLogoUrl = "https://developers.google.com/youtube/images/YouTube_logo_standard_white.png";
var googleLogoBlob = UrlFetchApp
.fetch(googleLogoUrl)
.getBlob()
.setName("googleLogoBlob");
var youtubeLogoBlob = UrlFetchApp
.fetch(youtubeLogoUrl)
.getBlob()
.setName("youtubeLogoBlob");
MailApp.sendEmail({
to: "recipient#example.com",
subject: "Logos",
htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
"inline YouTube Logo <img src='cid:youtubeLogo'>",
inlineImages:
{
googleLogo: googleLogoBlob,
youtubeLogo: youtubeLogoBlob
}
});
}
The email is not sent at all and the code doesn't appear to execute.
When I remove the first 4 statements (setting up the URLs and blobs), and the inlineImages section of the sendEmail function, the email is sent.
What am I doing wrong?
I have no problem with your code.