I couldn’t figure out how to send an email with both the subject and from set from the command line.
-
mail -s "my subject" example@foo.bar
worked with mail but would only set the subject.
-
sendmail -f "sender@foo.bar" receiver@foo.bar
worked with sendmail but would only set the “from”. With a little help from Google I put this together:
-
#!/bin/bash
-
-
HOST=`hostname | awk 'BEGIN { FS="." } ; {print $1}'`
-
DOMAIN=`hostname`
-
-
PASSWORD='mypassword'
-
-
BODY=`tail -n 40 /var/log/maillog`
-
-
FROM="$HOST@$DOMAIN"
-
TO='receiver@foo.bar'
-
SUBJECT="Last 40 lines of maillog"
-
-
(
-
echo "From: $FROM"
-
echo "Subject: $SUBJECT"
-
echo "To: $TO"
-
echo "$BODY"
-
) | sendmail -f $FROM $TO
