The Apps Script Lab

Automatically Email Google Form Submissions (Including File Uploads) 📨

Ever wished you could get an instant email when someone submits your Google Form complete with their answers and any files they uploaded? With a few lines of Apps Script, you can!

Let’s break it down 🕵️

🧩 Why Use This Script?

This solution answers a common need: getting notified via email when someone submits a form response. Especially useful when:

Let’s break it down 🕵️

In my experience, many people aren’t aware that you can actually embed an Apps Script project directly into a Google Forms. 

Just like with Google Sheets, you can add custom menus, user interfaces, and powerful automations. Plus, Forms come with their own set of unique triggers you can take advantage of!

This function automatically sends an email to a specified recipient when a form is submitted.

It collects the user’s responses and loops through them to build the HTML body of the email.

If a response is of the FILE_UPLOAD type, the script retrieves the uploaded file and includes it as an attachment in the email.

You can check the full list of item types here, and handle each response accordingly!

Apps Script Viewer
JSCode.gs
/**
 * Function triggered upon form submission to send email with form responses.
 * @param {Object} e - The event object that contains the form response.
 */
function onFormSubmit(e) {

  // Recipient email
  const recipient = "lidia@gmail.com";

  // Extract the form responses
  const responses = e.response.getItemResponses();

  const submitter = e.response.getRespondentEmail();

  console.log(responses)

  // Create the email subject and body
  let subject = `New application received`;
  let htmlBody = `Application submitted by ${submitter}:`;
  let img;

  // Loop through the responses and create bullet points
  for (let i = 0; i < responses.length; i++) {
    let itemResponse = responses[i];
    if (itemResponse.getItem().getType() == "FILE_UPLOAD") {
      const answer = itemResponse.getResponse();
      img = DriveApp.getFileById(answer);
    } else {
      const question = itemResponse.getItem().getTitle();
      const answer = itemResponse.getResponse();
      htmlBody += `${question}: ${answer}`;
    }
  }

  htmlBody += ``;

  // Send the email
  GmailApp.sendEmail(recipient, subject, "", {
    htmlBody: htmlBody,
    attachments: img
  });
}

On your right panel, access the trigger section and click “Add a trigger”

Select the function to launch, here onFormSubmit, and chose the
event type “When submitting the form”, then save.

Heads up! ⚠️

Before your function can run properly on form submission, you need to authorize the necessary scopes your script uses. To do this, just run any function manually from the script editor, this will trigger the authorization prompt. Approve it, and you’re good to go!

 

You’re all set! Want to take it a step further? You could:

Scroll to Top