Last active
October 8, 2021 23:47
-
-
Save bahamat/e4e7a10fdd8cff0cce1880b48abfadac to your computer and use it in GitHub Desktop.
Using curl to send mail via SMTP
This file contains 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 | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
# Copyright 2014 Brian Bennett | |
if [[ -n "$TRACE" ]]; then | |
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' | |
set -o xtrace | |
fi | |
usage () { | |
printf '%s -f from -t to -s server [ -p port ]\n' "${0##*/}" | |
exit $1 | |
} | |
while getopts ":f:t:s:p" options; do | |
case $options in | |
f ) from="${OPTARG}" ;; | |
t ) to="${OPTARG}" ;; | |
s ) server="${OPTARG}" ;; | |
p ) port="${OPTARG}" ;; | |
h ) usage 0 ;; | |
* ) usage 1 ;; | |
esac | |
done | |
curl -sv --mail-from "${from:?}" --mail-rcpt "${to:?}" -T - "smtp://${server:?}:${port:-25}" << EOF | |
From: ${from} | |
To: ${to} | |
Subject: test message to ${to} from ${from} | |
Test submission to ${server}. | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment