简体   繁体   中英

Google Form: Include hyperlink in Email of the Doc's Google Drive location

I am using a Google Form to email a completed PDF to the user who submitted the form. The script is also saving a Google Doc copy on Google Drive. Everything works great except one thing. I would like to include this hyperlink in the body of the email with the PDF attached. Below are the scripts I am using to save and send the email.....

to save and close the temporary document:

copyDoc.saveAndClose();

to convert temporary document to PDF:

var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

to attach PDF and send the email:

var subject = "Name";
var body = "Attached is the Auto-Generated PDF;
MailApp.sendEmail(user_email, subject, body, {htmlBody: body, attachments: pdf});

A hyperlink in HTML is an <a> tag.

<a href="http://www.stackoverflow.com">Stack Overflow</a>

To incorporate the URL into the document, you'll need to use a JavaScript text formula. You can concatenate text with the plus sign.

"<a href='" + urlToDoc + "'>Stack Overflow</a>"

You need to somehow get the URL of the new Doc, and put that URL into a variable.

var fileNewDoc = DriveApp.getFileById(copyId);
var urlToDoc = fileNewDoc.getUrl();

Google Documentation - File Class - getUrl() Method

So the code would be something like this:

var fileNewDoc = DriveApp.getFileById(copyId);
var urlToDoc = fileNewDoc.getUrl();

var pdf = fileNewDoc.getAs("application/pdf");

var body = "Attached is the Auto-Generated PDF. <br><br>";
body = body + "<a href='" + urlToDoc + "'>Your Link to the Copy</a>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM