I've setup a trigger with the following code to send out an email everytime an employee submits a request. What this basically does is send out a brochure (in PNG format and stored in Google Drive). Somehow, the code does not work. Spent almost the entire day scouring the net for answers, but none helped. I tried the DriveApp.getFileByID method and it worked, but that was just for one file. The attachment depends on the product that the employee selects on the Google form, and that is dynamic.
Any help is much appreciated. Thanks!
function SendBrochure(e) {
try {
var email = e.values[1];
var subject = "ABC Co - Information you requested";
var msgcc = "[email protected]";
var aliases = GmailApp.getAliases();
var cxnm = e.values[2] + " " + e.values[3] + " " + e.values[4];
var msgl1 = "Greetings from ABC Co, " + cxnm + ".";
var emailText = "<b>Greetings from ABC Co, " + cxnm + ". </b> <p>With reference to your conversation
with us and your request for information, please find attached herein the same.</p> <p> Should you
require further assistance, please contact the undersigned, or refer to the brochure for pertinent
site contact details.</p> <p>We appreciate your interest and look forward to your visit soon.</p>
<p> Thanks and regards, <br><b>ABC Co</b><br>Tel: +1 202 555 1212<br>Web:
www.abc.com </p>";
var brochurename = e.values[5]; //gets file name from form (already filled in - for e.g f_1.png)
var brochure1 = DriveApp.getFilesByName(brochurename);
GmailApp.sendEmail(email, subject, msgl1, {
name: 'ABC Co',
attachments: [brochure1.next()],
htmlBody: emailText,
from: aliases[1]
});
GmailApp.sendEmail(msgcc, "Email sent!", "Your email request to " + email + " has been completed successfully at " + e.values[0], {
'from': aliases[1]
});
} catch (e) {
Logger.log(e.toString());
}
}