Hello, I was just wondering if it would be able to send an email by just making an http request ?
Thank you.
@werthd what is the _use-case_? (_what are you trying to achieve with this_...?)
(_the short answer is: Yes. The "long answer" is another question: Why?_)
It is for personal usage only, i am not quiet sure what exactly i am going to do with it but probably custom notifications for myself from either my website or from my Python-Scripts. I know that Python is capable of sending those emails. Btw: your script is the only way for me to send Emails from my webspace.
@werthd is your idea to receive a _notification_ when the person first "_lands_" on the page?
Yes the mail should be send without any interaction(for example Pressing a button).
@werthd you can _easily_ "piece" this script together from the instructions in the first section of the readme. Only difference is you aren't really submitting a form.
If you already have JQuery on the page, you can achieve this in about 6 lines of code:
var googleFormUrl = "https://script.google.com/macros/s/your-script-url"
$( document ).ready(function() {
$.post(googleFormUrl, function( data ) {
console.log(data)
});
});
Then the Google Apps Script is just:
function doPost(e) {
var sendEmailTo = "[email protected]"
MailApp.sendEmail({
to: String(sendEmailTo),
subject: "Page Loaded",
htmlBody: "<p>Page Loaded</p>"
});
}
Hope that helps.
If you want to get "fancy" do a bit of Googling. 馃憤
My page looks like this now:
<html>
<head>
<script src="jquery-3.3.1.min.js"></script>
</head>
<script>
var googleFormUrl = "https://script.google.com/macros/s/**********"
$( document ).ready(function() {
$.post(googleFormUrl, function( data ) {
console.log(data)
});
});
function doPost(e) {
var sendEmailTo = "[email protected]"
MailApp.sendEmail({
to: String(sendEmailTo),
subject: "Page Loaded",
htmlBody: "<p>Page Loaded</p>"
});
}
</script>
</html>
I now get: {result: "error", error: {鈥}
@werthd the function doPost(e) ... needs to be on Google Script.
see: section 3 of the tutorial:
https://github.com/dwyl/html-form-send-email-via-google-script-without-server#3-set-the-to_address-in-the-script
If you just want to know when someone lands on your page... there are many tools out there for analytics that are much more powerful than a simple email, e.g. Google Analytics (but there are many more, a number of which are free).
If you -need- an email whenever this occurs, you can follow @nelsonic 's awesome steps above to get it working, though. Just bear in mind that Google's APIs do limit emails per day, something like 100, so this approach wouldn't scale.
@werthd let us know if you are still having difficulty with the form! it sounded like you had a few things to fix up, but post back/reopen if it isn't working. alternatively, feel free to use other forums, such as StackOverflow to post for help from others more generally.