Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active May 9, 2019 04:03
Show Gist options
  • Save coderofsalvation/8270415 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8270415 to your computer and use it in GitHub Desktop.
simple bash email function using sendmail
# sends email using sendmail
# usage: echo "my email message" | email "foo@bar.com" "new event happened" "serverX" "noreply@serverx.com"
email(){
content="$(cat - )"; email="$1"; subject="$2"; fromname="$3"; from="$4"
{
echo "Subject: $subject"
echo "From: $fromname <$from>";
echo "To: $email";
echo "$content"
} | $(which sendmail) -F "$from" "$email"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment