How to receive email notification from google form with attached content and image
Many Google Forms add-ons available on the Google Workspace Marketplace provide only basic email notification functionality. However, these notifications are often limited, requiring users to subscribe to a monthly plan without granting access to the actual content of the Google Form. The AppScript code below offers a viable solution. It can be adapted to ensure users receive detailed emails upon form submission, even handling forms with attachments.
The appscript code was implemented with the form below
function sendFormResponseEmail(e) {
var formResponse = e.response;
var recipientEmail = "example@gmail.com"; // Change to the recipient's email address.
var subject = "New Form Response with Attached Image";
// Create an empty message with HTML formatting.
var message = "<html><body>New form submission received:<br><br>";
// Get the respondent's name and phone number.
var nameResponse = formResponse.getResponseForItem(FormApp.getActiveForm().getItems(FormApp.ItemType.TEXT)[0]);
var phoneResponse = formResponse.getResponseForItem(FormApp.getActiveForm().getItems(FormApp.ItemType.TEXT)[1]);
// Extract name and phone number from the responses.
var name = nameResponse.getResponse();
var phone = phoneResponse.getResponse();
// Get the URL of the attached image.
var imageResponse = formResponse.getResponseForItem(FormApp.getActiveForm().getItems(FormApp.ItemType.FILE_UPLOAD)[0]);
var imageUrl = imageResponse.getResponse();
// Embed the image as an attachment.
var attachments = [DriveApp.getFileById(imageUrl)];
// Build the email message.
message += "Name: " + name + "<br>";
message += "Phone Number: " + phone + "<br>";
// Close the HTML body.
message += "</body></html>";
// Send the email with HTML content and the image as an attachment.
MailApp.sendEmail({
to: recipientEmail,
subject: subject,
htmlBody: message,
attachments: attachments
});
}
Copy Code
An understanding of the indexing will make tweaking of the code very easy, watch and understand the YouTube video well. If there are any roadblocks in your implementation of this code, talk to us.