Skip to content

Instantly share code, notes, and snippets.

@xyzkpz
Forked from nikoheikkila/sendmail.sh
Created September 25, 2021 10:18
Show Gist options
  • Save xyzkpz/eaf99f96506036b2ea0ec77544d2345c to your computer and use it in GitHub Desktop.
Save xyzkpz/eaf99f96506036b2ea0ec77544d2345c 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