@ -5,6 +5,7 @@
#MAIL_BIN="sendmail"
#MAIL_BIN="sendmail"
#MAIL_FROM="yyyy@gmail.com"
#MAIL_FROM="yyyy@gmail.com"
#MAIL_TO="yyyy@gmail.com"
#MAIL_TO="yyyy@gmail.com"
#MAIL_NOVALIDATE=""
mail_send( ) {
mail_send( ) {
_subject = " $1 "
_subject = " $1 "
@ -14,22 +15,28 @@ mail_send() {
_debug "_content" " $_content "
_debug "_content" " $_content "
_debug "_statusCode" " $_statusCode "
_debug "_statusCode" " $_statusCode "
MAIL_NOVALIDATE = " ${ MAIL_NOVALIDATE :- $( _readaccountconf_mutable MAIL_NOVALIDATE) } "
if [ -n " $MAIL_NOVALIDATE " ] ; then
_saveaccountconf_mutable MAIL_NOVALIDATE 1
else
_clearaccountconf "MAIL_NOVALIDATE"
fi
MAIL_BIN = " ${ MAIL_BIN :- $( _readaccountconf_mutable MAIL_BIN) } "
MAIL_BIN = " ${ MAIL_BIN :- $( _readaccountconf_mutable MAIL_BIN) } "
if [ -n " $MAIL_BIN " ] && ! _exists " $MAIL_BIN " ; then
if [ -n " $MAIL_BIN " ] && ! _exists " $MAIL_BIN " ; then
_err " It seems that the command $MAIL_BIN is not in path. "
_err " It seems that the command $MAIL_BIN is not in path. "
return 1
return 1
fi
fi
_MAIL_CMD = $( _mail_cmnd)
_MAIL_BIN = $( _mail_bin )
if [ -n " $MAIL_BIN " ] ; then
if [ -n " $MAIL_BIN " ] ; then
_saveaccountconf_mutable MAIL_BIN " $MAIL_BIN "
_saveaccountconf_mutable MAIL_BIN " $MAIL_BIN "
else
else
_clearaccountconf "MAIL_BIN"
_clearaccountconf "MAIL_BIN"
fi
fi
_MAIL_BODY = $( _mail_body)
MAIL_FROM = " ${ MAIL_FROM :- $( _readaccountconf_mutable MAIL_FROM) } "
MAIL_FROM = " ${ MAIL_FROM :- $( _readaccountconf_mutable MAIL_FROM) } "
if [ -n " $MAIL_FROM " ] ; then
if [ -n " $MAIL_FROM " ] ; then
if ! _contains " $MAIL_FROM " "@ "; then
if ! _mail_valid " $MAIL_FROM " ; then
_err " It seems that the MAIL_FROM= $MAIL_FROM is not a valid email address. "
_err " It seems that the MAIL_FROM= $MAIL_FROM is not a valid email address. "
return 1
return 1
fi
fi
@ -39,7 +46,7 @@ mail_send() {
MAIL_TO = " ${ MAIL_TO :- $( _readaccountconf_mutable MAIL_TO) } "
MAIL_TO = " ${ MAIL_TO :- $( _readaccountconf_mutable MAIL_TO) } "
if [ -n " $MAIL_TO " ] ; then
if [ -n " $MAIL_TO " ] ; then
if ! _contains " $MAIL_TO " "@ "; then
if ! _mail_valid " $MAIL_TO " ; then
_err " It seems that the MAIL_TO= $MAIL_TO is not a valid email address. "
_err " It seems that the MAIL_TO= $MAIL_TO is not a valid email address. "
return 1
return 1
fi
fi
@ -55,8 +62,9 @@ mail_send() {
contenttype = "text/plain; charset=utf-8"
contenttype = "text/plain; charset=utf-8"
subject = " =?UTF-8?B? $( echo " $_subject " | _base64) ?= "
subject = " =?UTF-8?B? $( echo " $_subject " | _base64) ?= "
result = $( { echo " $_MAIL_BODY " | eval " $_MAIL_CMD " ; } 2>& 1)
result = $( { _mail_body | eval " $( _mail_cmnd) " ; } 2>& 1)
# shellcheck disable=SC2181
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ] ; then
_debug "mail send error."
_debug "mail send error."
_err " $result "
_err " $result "
@ -67,7 +75,7 @@ mail_send() {
return 0
return 0
}
}
_mail_cmnd ( ) {
_mail_bin ( ) {
if [ -n " $MAIL_BIN " ] ; then
if [ -n " $MAIL_BIN " ] ; then
_MAIL_BIN = " $MAIL_BIN "
_MAIL_BIN = " $MAIL_BIN "
elif _exists "sendmail" ; then
elif _exists "sendmail" ; then
@ -83,6 +91,10 @@ _mail_cmnd() {
return 1
return 1
fi
fi
echo " $_MAIL_BIN "
}
_mail_cmnd( ) {
case $( basename " $_MAIL_BIN " ) in
case $( basename " $_MAIL_BIN " ) in
sendmail)
sendmail)
if [ -n " $MAIL_FROM " ] ; then
if [ -n " $MAIL_FROM " ] ; then
@ -105,16 +117,22 @@ _mail_cmnd() {
}
}
_mail_body( ) {
_mail_body( ) {
if [ " $_MAIL_BIN " = "sendmail" ] || [ " $_MAIL_BIN " = "ssmtp" ] ; then
if [ -n " $MAIL_FROM " ] ; then
echo " From: $MAIL_FROM "
fi
case $( basename " $_MAIL_BIN " ) in
sendmail | ssmtp)
if [ -n " $MAIL_FROM " ] ; then
echo " From: $MAIL_FROM "
fi
echo " To: $MAIL_TO "
echo " Subject: $subject "
echo " Content-Type: $contenttype "
echo
fi
echo " To: $MAIL_TO "
echo " Subject: $subject "
echo " Content-Type: $contenttype "
echo
; ;
esac
echo " $_content "
echo " $_content "
}
}
_mail_valid( ) {
[ -n " $MAIL_NOVALIDATE " ] || _contains " $1 " "@"
}