I have a template made up of placeholders, example {{NAME}} {{SURNMANE}} {{WEBSITE}} where, through AppScript I insert the text. In the case of {{WEBSITE}} I would need to enter the name of the clickable site, therefore with a HYPERLINK inside it.
emailBody = emailBody.replace(/{{NAME}}/g, ""+name);
emailBody = emailBody.replace(/{{SURNAME}}/g,""+surname);
emailBody = emailBody.replace(/{{WEBSITE}}/g,""+website);
//"CompanyWebSite" , but I would like to add "hyperlink=www.companywebsite.com/home/..."
Thanks!
Related
when member in telegram group has already sent a photo in to telegram group , now he edits the image and updates caption text with EDIT option in telegram , the new updated caption he made is needed in google sheets.
Now already using below for Caption which is working fine, but when the image is EDITED its not capturing
var data = JSON.parse(e.postData.contents);
var caption = data.message.caption ;
SpreadsheetApp.openById(ssId).getSheets()[0].appendRow([new Date(),caption ]);
Try changing this to :-
var caption = data.message.caption
this :-
var caption = data.edited_message.caption
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
I've built an HTML file inside the Google Script code editor.
Inside the HTML I've included placeholders, such as {{NAME}}.
My goal is to replace these placeholders with data from a Google Sheet.
Well...it's not working :)
The email is received with just HtmlOutput in the body.
Code below. What am I missing?
var emailBody = HtmlService.createHtmlOutputFromFile('client_intro_email');
emailBody = emailBody.replace({{NAME}}, clientname);
GmailApp.sendEmail(clientemail, 'subject', '',
{htmlBody: emailBody.getContent(),
}
Hi {{NAME}},
Here are the variables I'd like to push into the HTML. Content of the cells is text.
var clientname = spreadsheet.getRange('C2').getValue();
var clientemail = spreadsheet.getRange('P2').getValue();
Answer:
You can use templated HTML to dynamically insert HTML content from your script.
More Information:
From the documentation on scriptlets:
Apps Script templates can contain three special tags, called scriptlets. Inside a scriptlet, you can write any code that would work in a normal Apps Script file: scriptlets can call functions defined in other code files, reference global variables, or use any of the Apps Script APIs. You can even define functions and variables within scriptlets, with the caveat that they can't be called by functions defined in code files or other templates.
So, you can create an HTML Template file (from the File > New > HTML file menu item in the Apps Script UI) and set it up ready to receive data from whatever your Apps script function processes.
Setting up your HTML:
As a simple example, you can create an HTML file called emailTemplate.html which contains the following data:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
Hi <?!= name ?>, your email address is <?!= email ?>.
</body>
</html>
Then in your Code.gs file, you can load the data you want directly into your HTML template before evaluating it:
var htmlTemplate = HtmlService.createTemplateFromFile('emailTemplate.html');
var clientname = spreadsheet.getRange('C2').getValue();
var clientemail = spreadsheet.getRange('P2').getValue();
htmlTemplate.email = clientemail;
htmlTemplate.name = clientname;
var emailBody = htmlTemplate.evaluate();
GmailApp.sendEmail(clientemail, 'subject', '',
{
htmlBody: emailBody.getContent(),
});
This mitigates any need to do replacing with emailBody.replace({{NAME}}, clientname); as the template is directly loaded with the variables that have been set in Apps Script.
For a person called John Doe with an email address of john.doe#example.com, the above example will send an email which will appear as:
Hi John Doe, your email address is john.doe#example.com.
References:
HTML Service: Templated HTML | Apps Script | Google Developers
I wrote a script that creates a new Spreadsheet from one of the Sheets of the original Spreadsheet and emails the new Spreadsheet with the PDF version attached and has an html body with some text and the link to the new Spreadsheet. The script fires each morning because the Sheet has dynamically chaning data, so the link also changes with every trigger.
The problem is that the link in the html body appears as a text and I would like it to be clickable. I tried formatting it with with A HREF but that wouldn't seem to do the trick
var napijelentes = SpreadsheetApp.create(fajlnev);
var napijelentesfajlid = napijelentes.getId();
var napijelentesfajl = DriveApp.getFileById(napijelentesfajlid);
var napijelentesurl = napijelentes.getUrl();
MailApp.sendEmail({
to: ellenorzes,
subject: subject,
htmlBody: "To download the spreadsheet please follow the link below: <br>" + napijelentesurl + "<br><br>",
attachments: [napijelentesfajl]
});
This way the link appears in the email as plain text, with [napijelentesurl] in front of it and is still not clickable.
Any solutions to my problem?
Create a variable for the html string.
var h;
h = 'To download <br><a href = "' + napijelentesurl + '">' +
napijelentesurl + "</a><br><br>";
Use single quotes on the ends of string that need double quotes inside the string.
I am trying to send a Google Document (nothing fancy here, just a simple, script-built text document) as a plain text email attachment with Google Apps Script. I can do this manually by going into my Drive and selecting "File>Email As Attachment...". From there, a window pops up asking for the recipients, file type (Where I can choose plain text), subject, message, etc. How can I do this through script?
I have another document using the following for PDFs (Where TimeDataId and email_address are properly defined):
//Get Data as .pdf file
var TimeData = DocsList.getFileById(TimeDataId).getAs('application/pdf');
// Attach pdf and send the email to customer
var subject = 'Time Data';
var body = 'Please see the attached Data.' + '<br/><br/>Thank you,';
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: TimeData});
And this works flawlessly for PDFs. However, I am really looking for something like this:
//Get Data as .txt file
var TimeData = DocsList.getFileById(TimeDataId).getAs(MimeType.PLAIN_TEXT);
// Attach txt and send the email to customer
var subject = 'Time Data';
var body = 'Please see the attached Data.' + '<br/><br/>Thank you,';
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: TimeData});
All I ever get with this method is a failure notice with the report of "Authorization is required to perform that action".
I know I could just paste the plain text information into the body of my email, but I would really like to have a downloadable file, as this saves a step for the user (this file will be used later for data import into another program). Has this question already been asked and answered? Does anyone have any ideas? Thanks for any input.
Here is how I would get text from a Document as a plain text file.
var txt = DocumentApp.openById(TimeDataId).getText();
var TimeData = Utilities.newBlob(txt, 'text/plain','myattachment.txt')
It takes an extra level of indirection but for now getAs is only supported for PDFs.
I believe you are getting that error message as the MimeType class for the new DriveApp but I haven't verified that.