SMTP tools
This commit is contained in:
parent
825d91b462
commit
026220fe26
53
bin/email-via-mailgun-smtp
Executable file
53
bin/email-via-mailgun-smtp
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
err() {
|
||||
>&2 echo "ERROR: $@"; usage; exit 1
|
||||
}
|
||||
|
||||
warn() {
|
||||
>&2 echo "$@"
|
||||
}
|
||||
|
||||
usage() { >&2 cat <<USAGEDOC
|
||||
usage:
|
||||
email-via-mailgun-smtp [recipient] [subject] [username] [password] <<< 'Hello, world!'
|
||||
|
||||
email-via-mailgun-smtp will read all the input from stdin and use the contents as the body of the email.
|
||||
recipient will default to DEFAULT_MAILGUN_SMTP_RECIPIENT if not set
|
||||
username will default to DEFAULT_MAILGUN_SMTP_USERNAME if not set
|
||||
password will default to DEFAULT_MAILGUN_SMTP_PASSWORD if not set
|
||||
subject will default to DEFAULT_MAILGUN_SMTP_SUBJECT if not set
|
||||
USAGEDOC
|
||||
}
|
||||
|
||||
recipient="${1:-$DEFAULT_MAILGUN_SMTP_RECIPIENT}"; shift
|
||||
[[ -z $recipient ]] && err 'No recipient provided.'
|
||||
|
||||
subject="${1:-$DEFAULT_MAILGUN_SMTP_SUBJECT}"; shift
|
||||
[[ -z $subject ]] && warn 'No subject provided. Leaving blank.'
|
||||
|
||||
username="${1:-$DEFAULT_MAILGUN_SMTP_USERNAME}"; shift
|
||||
[[ -z $username ]] && err 'No username provided.'
|
||||
|
||||
password="${1:-$DEFAULT_MAILGUN_SMTP_PASSWORD}"; shift
|
||||
[[ -z $password ]] && err 'No password provided.'
|
||||
|
||||
warn "Reading email body from stdin..."
|
||||
|
||||
body=""
|
||||
while read -r line; do
|
||||
body="${body}\n${line}"
|
||||
done
|
||||
|
||||
echo "Recipient: $recipient"
|
||||
|
||||
warn "Finished reading body. Sending email..."
|
||||
|
||||
swaks --auth \
|
||||
--server smtp.mailgun.org \
|
||||
--au "$username" \
|
||||
--ap "$password" \
|
||||
--to "$recipient" \
|
||||
--h-Subject: "$subject" \
|
||||
--body "$body"
|
||||
|
|
@ -49,6 +49,7 @@ pacaur --needed -S \
|
|||
docker docker-compose `# Yummy containers` \
|
||||
inotify-tools `# Watching` \
|
||||
luajit lua luarocks `# Lua` \
|
||||
swaks `# SMTP CLI` \
|
||||
--noconfirm --noedit
|
||||
|
||||
# install rxvt-unicode script for resizing font on-the-fly
|
||||
|
|
Reference in a new issue