Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila
Created June 28, 2012 09:52
Show Gist options
  • Save nikoheikkila/3010346 to your computer and use it in GitHub Desktop.
Save nikoheikkila/3010346 to your computer and use it in GitHub Desktop.
Bash: Send mail from command-line
#!/bin/bash
# Send a simple mail from shell with this script
# Niko Heikkila 2012
TO=$1
SUBJECT=$2
MSG=$3
BODY=$HOME/message.tmp
# Add padding to email message
echo -e "\n\n" > "$BODY"
echo "$MSG" >> "$BODY"
echo -e "\r\n" >> "$BODY"
if [ -f "$BODY" ]
then
# Send mail if message exists
mail -s "$SUBJECT" "$TO" < "$BODY"
else
echo "Sending mail failed, please try again."
exit
fi
# Delete sent message
rm -f "$BODY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment