Skip to content

Instantly share code, notes, and snippets.

@ypchen
Last active February 15, 2018 10:20
Show Gist options
  • Save ypchen/5b1b1af9750cb54b6e1e88fe9a91d2f7 to your computer and use it in GitHub Desktop.
Save ypchen/5b1b1af9750cb54b6e1e88fe9a91d2f7 to your computer and use it in GitHub Desktop.
send a message to Mailgun
#!/bin/bash
# default
if [ -z ${CURL+x} ]; then
CURL="/usr/bin/curl"
fi
# mg_domain, api_key, MSG_SUBJ_PREFIX, MSG_FROM_EMAIL, & CURL if necessary
CONF="${HOME}/.Mailgun.conf"
source ${CONF}
if [ -z ${to_email+x} ]; then
to_email="${1}"
fi
if [ -z ${MSG_SUBJ_PREFIX+x} ]; then
MSG_SUBJ_PREFIX=""
fi
if [ -z ${subject+x} ]; then
subject="${MSG_SUBJ_PREFIX}${2}"
fi
if [ -z ${text+x} ]; then
text="${3}"
fi
if [ -z "${4}" ]; then
from_email="${MSG_FROM_EMAIL}"
else
from_email="${4}"
fi
${CURL} -s --user "api:${api_key}" \
https://api.mailgun.net/v3/${mg_domain}/messages \
-F from="${from_email}" \
-F to="${to_email}" \
-F subject="${subject}" \
-F text="${text}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment