79194898

Date: 2024-11-16 10:06:34
Score: 0.5
Natty:
Report link

Sending Email on Form Submit Using MailApp

I tried your code modified and added a solution, I created an Installable Trigger event on which on every form submit it will send the attachment along with the body content.

Code.gs on Spreadsheet

function onFormSubmit(e) {
  var responses = e.values;

  // Email subject file and body
  var email = responses[1]; // Assuming the email is on the first response
  var fileItem = responses[2]; // Assuming the file is the second response
  var subject = "New File Uploaded";
  var body = "A new file has been xuploaded.\n\n";

  if (fileItem) {
    body += responses
    MailApp.sendEmail(email, subject, body);
    Logger.log("File sent successfully!");
  }
}

Sample Output:

Sample Output

Sample Form:

Sample form

How to Install a Trigger Event:

In your form click the View in Sheets.

Sample 3

Click Extension > Apps Script.

Appscript

Click on Triggers.

Sample 5

New Trigger then add the function to change the event type to On form Submit.

Trigger Event

References:

Installable Triggers

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Lime Husky