Skip to content

Instantly share code, notes, and snippets.

@jschpp
Created August 24, 2016 15:26
Show Gist options
  • Save jschpp/e21bbd9d40667764be4cbc0f8b72bf52 to your computer and use it in GitHub Desktop.
Save jschpp/e21bbd9d40667764be4cbc0f8b72bf52 to your computer and use it in GitHub Desktop.
Takes a markdown file converts it to html and sends it per mutt. Script includes a mail check because I'm prone to typos in mail addresses
#!/bin/bash
filename=$1
mail_address=$2
mail_subject=$3
scriptname=`basename "$0"`
if [ "$#" -ne 3 ]; then
echo "Illegal number of parameters"
echo "Usage: $scriptname <filename> <mail_address> <subject_of_mail>"
exit 1
fi
# check mail
# taken mostly from http://stackoverflow.com/a/2138835/343867 on 24-08-2016 17:15
OLDIFS=$IFS
IFS="@"
set -- $mail_address
if [ "${#@}" -ne 2 ];then
>&2 echo "invalid email"
exit 1
fi
domain="$2"
dig $domain | grep "ANSWER: 1" 1>/dev/null
if [ $? -ne 0 ]; then
>&2 echo "domain invalid"
exit 1
fi
IFS=$OLDIFS
pandoc -s -S $filename -t html | mutt -e "set content_type=text/html" -s $mail_subject $mail_address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment