You can put scripts in /www/cgi-bin/ directory and execute them like this: http://192.168.1.1/cgi-bin/script
This way you will be able to execute commands through URL.
And regarding the emails, there is command that look like this:
echo -e "subject:test\nfrom:firstname.lastname@example.org\n\ntestestestestest" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -starttls smtp" -f email@example.com -au"firstname.lastname@example.org" -ap"lalalal" email@example.com
To set it up: https://myaccount.google.com/ > Security > App Passwords
You can program your script to execute commands and then send email as the response/status of executed command and it's output.