0

I,m making a script that sends an email to my gmail account when a user fils a form.

With the simplest call:

MailApp.sendEmail("[email protected]","The Subject","The text on body");

When the script gets this function shows the error:

Uncaught ReferenceError: MailApp is not defined

The script is inside a function called when a form is submitted.

function FormSubmit(){
 MailApp.sendEmail("[email protected]","The Subject","The text on body");
}

This is just the code, without any variable. Only plain text (at the moment).

Thanks (again).

4
  • 1
    most likely you are calling it from client javascript, not server side.
    – Zig Mandel
    Oct 6, 2016 at 13:55
  • Could you explain that please? Thanks
    – Luis Gar
    Oct 6, 2016 at 14:50
  • show us how you call FormSubmit
    – Zig Mandel
    Oct 6, 2016 at 15:46
  • You had reason. I was calling from client (the html file) instead from server (the .gs file). Thanks, your comment helped me.
    – Luis Gar
    Oct 7, 2016 at 7:28

3 Answers 3

0

please review the documentation on MailApp here

You need to tell it what attribute goes where. Your code should look like this instead:

MailApp.sendEmail({to:"[email protected]",
                   subject:"The Subject",
                   body:"The text on body"}
                 );

Whitespaces not mandatory of course, so it can just as well be all in one line

3
  • Hi thanks. But that code makes the same error. I,ve just tested it.
    – Luis Gar
    Oct 6, 2016 at 9:04
  • Then it may have been something with the Google services. I just used the code and was able to set up a trigger on a form to run this. I received the e-mail without any problems.
    – Vytautas
    Oct 6, 2016 at 12:06
  • Have you set the script to run as yourself, and then authorised it to send mail on your behalf? Oct 6, 2016 at 13:48
0

If you've followed the correct syntax according to Google's spec, then it should be an error with Google's systems. Raise an issue with them.

1
  • Hi. Tested any ways. Run as myself, as anyone, given rights to mail... So, It's possible to be issue. Going there. Thanks!
    – Luis Gar
    Oct 6, 2016 at 14:49
0

Thanks everyone. I was sure the answer was very simple, and of course... Zig Mandel got that. I was trying into the client side. So the html file with some javascript, and it must be put on the .gs file. Now works Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.