Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
Google App Script Error - Cannot read property 'response' of undefined and Failed to send email: no recipient

I have a simple script that executes once form submit. It is a simple test script applied html for email.

function sendEmail(e) {
  
  //response
  //getRespondentEmail()
  var html = HtmlService.createTemplateFromFile("email.html");
  var htmlText = html.getCode();
  
  var emailTo = e.response.getRespondentEmail();
  var subject = "Thanks for participating";
  var textBody = "This email requries HTML support, please maek sure you open with a client taht support.";
  var options = { htmlBody: htmlText };
  
  
  if(emailTo !== undefined){
    GmailApp.sendEmail(emailTo,subject,textBody,options);
  //(recipient, subject, body, options)
  }
}

But it always noticed TypeError: Cannot read property 'response' of undefined.

TypeError: Cannot read property 'response' of undefined (line 8, file "Code")

either the respose from my host email said 'Failed to send email: no recipient' enter image description here

I do not know why it does not work, but I see someone successfully applied through above google app script.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

'e' undefined:

TypeError: Cannot read property 'response' of undefined

This error means the parameter e is undefined. Which means this function is not executing via trigger.

When functions are called by triggers, the function is passed an event object as argument. But in other contexts (for example, when executing this manually, from the editor) this argument is not passed.

Therefore, this function is supposed to get executed automatically when users submit the form. Don't try to execute it manually from the editor, if you are using e inside the function.

No recipient:

Failed to send email: no recipient

This means emailTo is not defined, which means getRespondentEmail() is not returning anything.

This could happen for two reasons:

  • Either a form response was created by the script, but not submitted. Since this is getting executed via a form submission trigger, though, it's not your case.
  • The other reason, which is most likely what's going here, is that you didn't enable the option to collect the email addresses. You can do that programmatically, by calling Form.setCollectEmail(collect), or through the UI, by following the guide in Collect respondents' email addresses.

Related:

  • How can I test a trigger function in GAS?
  • Event Objects
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!