Capture HTML Form Responses in Google Sheets and send a Confirmation Email to the Form Submitter - forms

I want the script to send the created html email template email.html to the person who last submitted the form.
Below is the success message I get in the console:
Below is the actual email that is received by the person who submits the form:
The email.html is formatted correctly and appears perfectly when sent manually.
I hope this is reprex enough.
EDIT: Maybe it's easier if I include the code
function sendEmail () {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var data = ss.getRange(lr,3);
var email = data.getValue();
var message = HtmlService.createTemplateFromFile('email');
var subject = "Test Subject"
GmailApp.sendEmail(email,subject, message);
}

It's not clear why you are using HtmlService.createTemplateFromFile, but from the image it's clear there at least one error, the script misses two methods:
HtmlService.HtmlTemplate.evaluate() to evaluate the Templated HTML
HtmlService.HtmlOutput.getContent() to get the HTML from the HtmlService.HtmlOutput object returned by the previous method.
Another option that looks to be an error is the use of GmailApp.sendEmail(string,string,string) method, as the third parameter should be a string to be used as the email plain text content. If you want to pass HTML, instead use GmailApp.sendEmail(string,string,string, Object)
Related
Emailing Google Sheet range (with or without formatting) as a HTML table in a Gmail message
Sending an email in HTML and plain with a Gmail Apps Script
Google script inject html into html email
References
https://developers.google.com/apps-script/guides/html
https://developers.google.com/apps-script/guides/html/templates
https://developers.google.com/apps-script/reference/gmail/gmail-app#sendEmail(String,String,String)

Related

Send a personnalised email from a Google Form

I'm starting a new project. I have to send a confirmation email when someone purchases a book with my Google Form. By now, I can send an email when you complete the form but I can't put the name of the buyer and the number of books in the email. F.ex : Hello "John", you gonna receive your "3" books in a week.
I've tried something like this :
function sendEmail(e) {
var formreponse = e.responses;
var itemreponse = formreponse.getItemResponses();
var number= itemreponse[5].getResponse(); //because it's in the 5th columns of the spread sheets
var name= itemreponse[3].getResponse();
And then I just write a simple code like this
var TextToSend = "blablabla" + name + " blabla" + number + ".";
GmailApp.sendEmail(emailTo, subject, TextToSend, options);
But I've got an error message:
Cannot read property 'responses' of undefined.
And I don't know why!
It's very frustrating for me not to be able to finish this simple task.
Issues:
When running this function manually, through the editor, no event object is passed, and so e is undefined. You should not run this function manually.
responses is not a valid Event property of Form submit triggers.
Solution:
Install an onFormSubmit trigger, either manually or programmatically, so that the function will run automatically when the Form is submitted, and e will be populated.
Change e.responses to e.response:
var formreponse = e.response;
Reference:
Event Objects > Google Forms events > Form submit

Salesforce send Email by Apex

I'm making by a requirement a code able to send an E-mail to an specific list of E-mails, due the fact that I must to include the attachments of the record I decided to use an apex class instead an e-mail alert. This object (A custom object ) must populate some fields in an email template with some of the record´s fields. I implemented the following code
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(lista);
mail.setTemplateId('00X21000000QR22');
//mail.setWhatId(idMinuta);
mail.setTargetObjectId('005d0000005NMIx');
mail.setSaveAsActivity(false);
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (ContentVersion document: documents)
{
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(document.Title);
efa.setBody(document.VersionData);
fileAttachments.add(efa);
}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
I understood that to make the fields merge it´s necesary to use the WhatId method. In the related code, I have commented it because It generates an error (INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.)
My question is, if is it possible to do this with a custom object. I´m a little confuse with salesforce documentation beacuse it looks like the method supports a custom object, or maybe If I am forggeting something to include in the code.
If i keep the WhatID line commented, effectively the email is sent with the attachments and the Template but it is not populated.
I really need this kind of solution because the org have in this object at least 20 email templates, for me will be easier just to pass the Id of the template instead of makig a code with 20 different html codes for each situation
Thanks a lot
Please publish this question at Salesforce StackExcahnge https://salesforce.stackexchange.com/

text email template is not coming in the Mail

As per the requirement I am sending a pdf file attachment to some email ids,I thought to include some static text to show in the email and i created one text template and added in the code ,but the text is not showing in the email.
here is the code
I used setTemplateId to show the template...
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName(************************);
attach.setInline(false);
attach.Body = body;
Messaging.SingleEmailMessage mail = new
Messaging.SingleEmailMessage();
EmailTemplate et=[Select id from EmailTemplate where
name=:'CSPdfEmailtemplate'];
mail.setUseSignature(false);
mail.setToAddresses(Emailids);
mail.setTemplateId(et.id);//here i am giving the id of template
mail.setBccSender(true);
From the documentation a singleEmailMessage using a template needs to have the id of a contact, user or lead with setTargetObjectId(targetObjectId) so you will need to add that.

Retrieving gmail signature with google apps script

Is there a way to retrieve the signature of my Gmail account using Google Apps script?
I'm currently using Google Apps Script to send out emails and it would be nice to be able to append my email signature to the end of the email body because Google Apps Script doesn't automatically do so.
While the Gmail API doesn't expose the signature, you can use a workaroud to grab the signature from Gmail.
Create a new Gmail draft, put the word "signature" in the subject and save the draft.
The body will include the signature by default. Do not modify the body.
Save and Close the draft.
Go to Google Script editor and use this script to grab the signature.
function getGmailSignature() {
var draft = GmailApp.search("subject:signature label:draft", 0, 1);
return draft[0].getMessages()[0].getBody();
}
Unfortunately, We don't have any user level access to retrieve our signature but, We have workaround, you can append signature simply copy your signature as a HTML [ Browser inspect mode] code from Gmail UI add to script variable, You can append this HTML string at the end of every email.
You can make it dynamic like name and Email ID
Sample code
function myFunction() {
var signHTML =
'<br><br><br><br><table style="border-bottom:1px solid"><tbody><tr><td><table><tbody><tr><td><table style="padding-right:20px">'+
'<tbody><tr><td></td></tr></tbody></table></td><td><table><tbody><tr><td><font face="open sans, sans-serif">'+
'<span style="font-size: 12px;"><b>YOUR NAME</b></span></font></td></tr><tr><td><font face="open sans, sans-serif">'+
'<span style="font-size: 12px;"><b>DESIGNATION </b></span></font>'+
'</td></tr><tr><td><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-711-XXXX</span>'+
'</div><div><span style="font-family:open sans,sans-serif;font-size:12px">+91-XXX-8XXX09-XXXX</span></div>'+
'<div><a href="https://www.searce.com" style="text-decoration:blink;vertical-align:top" target="_blank">'+
'<span style="color:#000000;font-family:open sans,sans-serif;font-size:12px">www.yourComany.com</span></a>'+
'</div></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td></td></tr></tbody></table>';
MailApp.sendEmail({
to: Session.getActiveUser().getEmail(),
subject: "Upend signature at the end of mail",
htmlBody: "Dear User</b>Signature testing" +
signHTML,
});
}
It works we are using this. Hope it helps you. :)

Sending HTML email from Joomla! component

I am developing a Joomla!3.0/3.1 component that allows people to book a golf lesson online. When they complete the booking and process paypal payment, I want to send them a receipt/confirmation email.
I can do this fine and send the information in html or plain text format. However I don't like the fact that I now have view (email content) data within my controller code.
Is it possible to have a sort of template view file which can be parsed and sent as the contents instead? or am I stuck with it in my code?
Thanks,
Chris
On admin side create a section for editing your email template with Joomla's default editor
you an create an editor on the backend and open an html file inside that, for changing the styles ,formats content etc for users.
keep your template file as an HTML file on server and email sending time something like below.
function send_mail_account_pages($email_title,$greeting_text,$subject,$email_content,$user_email){
$config = JFactory::getConfig();
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$path = JPATH_BASE."/email_tmpl/";
$fp = fopen($path."email_tmpl.html","r");
$fsize = filesize($path."email_tmpl.html");
$fcontent = fread($fp,$fsize);
fclose($fp);
$date_format = date("M.d, Y");
$fcontent = str_replace("{email_page_title}",$email_title,$fcontent);
$fcontent = str_replace("{date}",$date_format,$fcontent);
$fcontent = str_replace("{greeting_text}",$greeting_text,$fcontent);
$fcontent = str_replace("{email_content}",$email_content,$fcontent);
$fcontent = str_replace("{thanks_text}",THANKS_TEXT,$fcontent);
$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $user_email, $subject, $fcontent,1);
}
This way you can make admin users to give access to change the template styles make sure admin users do not edit the {place holders}.
Hope its helps..
Add a configuration field to your component of type textarea or editor, and let the user write the email template. You should explain which tokens are available or at least provide a default text, such as
Dear {USERNAME},
today I received {NUM_MESSAGES} messages on your behalf,
and your profile has been viewed {NUM_PROFILEVIEWS} times.
Then simply replace the {TOKENS} in your code with str_replace.