mailx function is not working

Teja picture Teja · Feb 21, 2013 · Viewed 40.6k times · Source

I am trying to use mailx function to send an e-mail to my personal email address.But I never received an email.Can someone help me pls. Here is my command below.

PRI_EMAIL_SUBJECT="Some Blah Blah"
PRI_EMAIL_ADDRESS="[email protected]"
PRI_EMAIL_BODY="$PRI_SETS_RAN_SUCSFL_CNT no. of sets ran successfully."

echo "Sending e-mail"
mailx -s $PRI_EMAIL_SUBJECT $PRI_EMAIL_ADDRESS < $PRI_EMAIL_BODY
echo

Answer

tripleee picture tripleee · Aug 20, 2015

You cannot redirect a string. mailx <$FOO expands the variable FOO and attempts to find a file named like that. But since you (presumably) do not have a file named 3 no. of sets ran successfully. you get a redirection error, and the command fails.

To actually send the contents of the variable as email, try

echo "$PRI_EMAIL_BODY" | mailx

(or maybe use a here document).