-
-
Save kou1okada/9629c2ff31876ec0f3ada03f4a3fb3f4 to your computer and use it in GitHub Desktop.
mailsend.sh - Mail sending script with SMTPS and SMTP-AUTH using OpenSSL
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
#!/usr/bin/env bash | |
function PLAIN () | |
{ | |
local u p | |
read -p "Username: " u | |
read -p "Password: " -s p | |
[ -z "$u" -a -z "$p" ] && return | |
echo -en "$u\0$u\0$p" | base64 | |
} | |
function mailsend () # <server> <port> <mailaddr> | |
{ | |
local MAIL_FROM="<$3>" | |
local RCPT_TO="<$3>" | |
local SMTP_HOST=$1 | |
local SMTP_PORT=$2 | |
local plain="$(PLAIN)" | |
echo | |
{ | |
cat<<-EOD | |
EHLO localhost | |
${plain:+AUTH PLAIN ${plain}$'/n'}MAIL FROM: ${MAIL_FROM} | |
RCPT TO: ${RCPT_TO} | |
DATA | |
Subject: test | |
From: ${MAIL_FROM} | |
To: ${RCPT_FROM} | |
test | |
. | |
QUIT | |
EOD | |
sleep 1 | |
} | openssl s_client -quiet -verify_quiet -connect $SMTP_HOST:$SMTP_PORT ${SERVERNAME:+-servername SERVERNAME} | |
} | |
if [ "$0" = "$BASH_SOURCE" ]; then | |
if (( $# != 3 )); then | |
cat <<-EOD | |
Usage: ${0##*/} <server> <port> <mailaddr> | |
EOD | |
exit | |
fi | |
mailsend "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment