mail -s subject address
# Example 1 - Simple:
echo "This is the body."| mailx -s "mailx Test1" jsmith@abc.com
# Example 2 - Using Variables:
SUBJECT="mailx Test2"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
echo "$BODY" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"
# Example 3 - Attached File:
SUBJECT="mailx Test3"
EMAIL_ADDRESS="jsmith@abc.com"
BODY="This is the body of the message."
ATTACHED_FILE="/etc/hosts"
cat "$ATTACHED_FILE" | mailx -s "$SUBJECT" "$EMAIL_ADDRESS"