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:email@example.com\n\ntestestestestest" | sendmail -v -H "exec openssl s_client -quiet -connect smtp.gmail.com:587 -tls1 -starttls smtp" -f firstname.lastname@example.org -au"email@example.com" -ap"lalalal" firstname.lastname@example.org
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.