Teja
Teja

Reputation: 13524

mailx function is not working

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

Upvotes: 1

Views: 49585

Answers (3)

tripleee
tripleee

Reputation: 189307

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).

Upvotes: 1

suspectus
suspectus

Reputation: 17258

Use the -d option of mailx for debug output. This may indicate an issue with the mail transport.

mailx -d -s $PRI_EMAIL_SUBJECT $PRI_EMAIL_ADDRESS < $PRI_EMAIL_BODY

Upvotes: 0

Teja
Teja

Reputation: 13524

This perfectly works.

 echo "something" | mailx -v -s "subject" [email protected]

Upvotes: 0

Related Questions