3 #Support local mail app
6 #MAIL_FROM="yyyy@gmail.com"
7 #MAIL_TO="yyyy@gmail.com"
14 _statusCode
="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
15 _debug
"_subject" "$_subject"
16 _debug
"_content" "$_content"
17 _debug
"_statusCode" "$_statusCode"
19 MAIL_NOVALIDATE
="${MAIL_NOVALIDATE:-$(_readaccountconf_mutable MAIL_NOVALIDATE)}"
20 if [ -n "$MAIL_NOVALIDATE" ]; then
21 _saveaccountconf_mutable MAIL_NOVALIDATE
1
23 _clearaccountconf
"MAIL_NOVALIDATE"
26 MAIL_BIN
="${MAIL_BIN:-$(_readaccountconf_mutable MAIL_BIN)}"
27 if [ -n "$MAIL_BIN" ] && ! _exists
"$MAIL_BIN"; then
28 _err
"It seems that the command $MAIL_BIN is not in path."
31 _MAIL_BIN
=$
(_mail_bin
)
32 if [ -n "$MAIL_BIN" ]; then
33 _saveaccountconf_mutable MAIL_BIN
"$MAIL_BIN"
35 _clearaccountconf
"MAIL_BIN"
38 MAIL_FROM
="${MAIL_FROM:-$(_readaccountconf_mutable MAIL_FROM)}"
39 if [ -n "$MAIL_FROM" ]; then
40 if ! _mail_valid
"$MAIL_FROM"; then
41 _err
"It seems that the MAIL_FROM=$MAIL_FROM is not a valid email address."
45 _saveaccountconf_mutable MAIL_FROM
"$MAIL_FROM"
48 MAIL_TO
="${MAIL_TO:-$(_readaccountconf_mutable MAIL_TO)}"
49 if [ -n "$MAIL_TO" ]; then
50 if ! _mail_valid
"$MAIL_TO"; then
51 _err
"It seems that the MAIL_TO=$MAIL_TO is not a valid email address."
55 _saveaccountconf_mutable MAIL_TO
"$MAIL_TO"
57 MAIL_TO
="$(_readaccountconf ACCOUNT_EMAIL)"
58 if [ -z "$MAIL_TO" ]; then
59 _err
"It seems that account email is empty."
64 contenttype
="text/plain; charset=utf-8"
65 subject
="=?UTF-8?B?$(printf -- "%b
" "$_subject" | _base64)?="
66 result
=$
({ _mail_body |
eval "$(_mail_cmnd)"; } 2>&1)
68 # shellcheck disable=SC2181
70 _debug
"mail send error."
75 _debug
"mail send success."
82 for b
in $MAIL_BIN sendmail ssmtp mutt
mail msmtp
; do
89 if [ -z "$_MAIL_BIN" ]; then
90 _err
"Please install sendmail, ssmtp, mutt, mail or msmtp first."
100 case $
(basename "$_MAIL_BIN") in
102 if [ -n "$MAIL_FROM" ]; then
103 _MAIL_ARGS
="-f '$MAIL_FROM'"
107 _MAIL_ARGS
="-s '$_subject'"
110 if [ -n "$MAIL_FROM" ]; then
111 _MAIL_ARGS
="-f '$MAIL_FROM'"
114 if [ -n "$MAIL_MSMTP_ACCOUNT" ]; then
115 _MAIL_ARGS
="$_MAIL_ARGS -a '$MAIL_MSMTP_ACCOUNT'"
121 echo "'$_MAIL_BIN' $_MAIL_ARGS '$MAIL_TO'"
125 case $
(basename "$_MAIL_BIN") in
126 sendmail | ssmtp | msmtp
)
127 if [ -n "$MAIL_FROM" ]; then
128 echo "From: $MAIL_FROM"
132 echo "Subject: $subject"
133 echo "Content-Type: $contenttype"
134 echo "MIME-Version: 1.0"
143 [ -n "$MAIL_NOVALIDATE" ] || _contains
"$1" "@"