I was able to run the script for email automation using this code:
echo 'This is a test' | mail -s 'Test mail' email@example.com -- -f firstname.lastname@example.org
However, I would like to be able to add an additional value when I run the script i.e ./email_test.sh value—the value is a variable that I need to include on the email message body.
You can do this:
#!/bin/bash body=$1 echo $body | mail -s 'Test mail' email@example.com -- -f firstname.lastname@example.org
then call the script as you requests
./email_test.sh value but don't forget to make it executable using
chmod +x email_test.sh
Update: If you need to treat the email as a variable then you need to add it as
email=$2 just like we did with
body=$1 but the email will be the second argument in this case and same goes for the subject.