-
-
Save xyzkpz/eaf99f96506036b2ea0ec77544d2345c to your computer and use it in GitHub Desktop.
Bash: Send mail from command-line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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