Search code examples
google-apps-scriptgoogle-forms

Most straightforward way to programatically send Google form


I created a google form with google apps script and would like to have another script I can run to send out the form to a list of e-mail adresses. In the form editor UI I can (by clicking "Send") type in an e-mail adress and the corresponding recipient receives the link to the form. How can I do this programatically? I expected to have a method available but there is nothing like it in the forms documentation.


Solution

  • Use MailApp

    See the documentation here - https://developers.google.com/apps-script/reference/mail/mail-app#sendemailrecipient,-subject,-body

    MailApp.sendEmail("[email protected]",
                      "Subject",
                      "Content");
    

    With your list of emails you could do something like:

    listOfEmails.forEach(email => {
        MailApp.sendEmail(email,
                      "Subject",
                      "Please fill out this form: " + linkToForm);
    })
    

    Where listOfEmails is an array of strings containing the email addresses, and linkToForm is a string of the link to your form.