Last active
February 29, 2016 10:00
-
-
Save mrw34/e956c0951238c15a7e88 to your computer and use it in GitHub Desktop.
A primitive mailx emulator using bash, curl and Mailgun
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 | |
set -eu -o pipefail | |
cmd="curl -s --user 'api:$MAILGUN_API_KEY' https://api.mailgun.net/v2/$MAILGUN_DOMAIN/messages" | |
while getopts "r:c:b:s:a:E" opt; do | |
case $opt in | |
r) | |
cmd+=" -F from='$OPTARG'" | |
;; | |
c) | |
cmd+=" -F cc='$OPTARG'" | |
;; | |
b) | |
cmd+=" -F bcc='$OPTARG'" | |
;; | |
s) | |
cmd+=" -F subject='$OPTARG'" | |
;; | |
a) | |
cmd+=" -F attachment=@$OPTARG" | |
;; | |
E) | |
E=1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
while (( $# )); do | |
cmd+=" -F to='$1'" | |
shift | |
done | |
stdin=$(</dev/stdin) | |
[[ -z ${E-} ]] && [[ -z $stdin ]] && exit | |
cmd+=" -F text='$stdin'" | |
eval $cmd >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g. Send via API example: