Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
ae380cb2
Unverified
Commit
ae380cb2
authored
May 19, 2019
by
neil
Committed by
GitHub
May 19, 2019
Browse files
Merge pull request #2259 from honzahommer/notify-sendmail
Add mail notify
parents
cf4c6033
d83c9da8
Changes
1
Hide whitespace changes
Inline
Side-by-side
notify/mail.sh
View file @
ae380cb2
#!/usr/bin/env sh
# support local mail app
#Support local mail app
#MAIL_BIN="sendmail"
#MAIL_FROM="yyyy@gmail.com"
#MAIL_TO="yyyy@gmail.com"
mail_send
()
{
_subject
=
"
$1
"
...
...
@@ -10,6 +14,107 @@ mail_send() {
_debug
"_content"
"
$_content
"
_debug
"_statusCode"
"
$_statusCode
"
_err
"Not implemented yet."
return
1
MAIL_BIN
=
"
${
MAIL_BIN
:-
$(
_readaccountconf_mutable MAIL_BIN
)
}
"
if
[
-n
"
$MAIL_BIN
"
]
&&
!
_exists
"
$MAIL_BIN
"
;
then
_err
"It seems that the command
$MAIL_BIN
is not in path."
return
1
fi
_MAIL_CMD
=
$(
_mail_cmnd
)
if
[
-n
"
$MAIL_BIN
"
]
;
then
_saveaccountconf_mutable MAIL_BIN
"
$MAIL_BIN
"
else
_clearaccountconf
"MAIL_BIN"
fi
_MAIL_BODY
=
$(
_mail_body
)
MAIL_FROM
=
"
${
MAIL_FROM
:-
$(
_readaccountconf_mutable MAIL_FROM
)
}
"
if
[
-n
"
$MAIL_FROM
"
]
;
then
if
!
_contains
"
$MAIL_FROM
"
"@"
;
then
_err
"It seems that the MAIL_FROM=
$MAIL_FROM
is not a valid email address."
return
1
fi
_saveaccountconf_mutable MAIL_FROM
"
$MAIL_FROM
"
fi
MAIL_TO
=
"
${
MAIL_TO
:-
$(
_readaccountconf_mutable MAIL_TO
)
}
"
if
[
-n
"
$MAIL_TO
"
]
;
then
if
!
_contains
"
$MAIL_TO
"
"@"
;
then
_err
"It seems that the MAIL_TO=
$MAIL_TO
is not a valid email address."
return
1
fi
_saveaccountconf_mutable MAIL_TO
"
$MAIL_TO
"
else
MAIL_TO
=
"
$(
_readaccountconf ACCOUNT_EMAIL
)
"
if
[
-z
"
$MAIL_TO
"
]
;
then
_err
"It seems that account email is empty."
return
1
fi
fi
contenttype
=
"text/plain; charset=utf-8"
subject
=
"=?UTF-8?B?
$(
echo
"
$_subject
"
| _base64
)
?="
result
=
$(
{
echo
"
$_MAIL_BODY
"
|
eval
"
$_MAIL_CMD
"
;
}
2>&1
)
if
[
$?
-ne
0
]
;
then
_debug
"mail send error."
_err
"
$result
"
return
1
fi
_debug
"mail send success."
return
0
}
_mail_cmnd
()
{
if
[
-n
"
$MAIL_BIN
"
]
;
then
_MAIL_BIN
=
"
$MAIL_BIN
"
elif
_exists
"sendmail"
;
then
_MAIL_BIN
=
"sendmail"
elif
_exists
"ssmtp"
;
then
_MAIL_BIN
=
"ssmtp"
elif
_exists
"mutt"
;
then
_MAIL_BIN
=
"mutt"
elif
_exists
"mail"
;
then
_MAIL_BIN
=
"mail"
else
_err
"Please install sendmail, ssmtp, mutt or mail first."
return
1
fi
case
$(
basename
"
$_MAIL_BIN
"
)
in
sendmail
)
if
[
-n
"
$MAIL_FROM
"
]
;
then
echo
"'
$_MAIL_BIN
' -f '
$MAIL_FROM
' '
$MAIL_TO
'"
else
echo
"'
$_MAIL_BIN
' '
$MAIL_TO
'"
fi
;;
ssmtp
)
echo
"'
$_MAIL_BIN
' '
$MAIL_TO
'"
;;
mutt
|
mail
)
echo
"'
$_MAIL_BIN
' -s '
$_subject
' '
$MAIL_TO
'"
;;
*
)
_err
"Command
$MAIL_BIN
is not supported, use sendmail, ssmtp, mutt or mail."
return
1
;;
esac
}
_mail_body
()
{
if
[
"
$_MAIL_BIN
"
=
"sendmail"
]
||
[
"
$_MAIL_BIN
"
=
"ssmtp"
]
;
then
if
[
-n
"
$MAIL_FROM
"
]
;
then
echo
"From:
$MAIL_FROM
"
fi
echo
"To:
$MAIL_TO
"
echo
"Subject:
$subject
"
echo
"Content-Type:
$contenttype
"
echo
fi
echo
"
$_content
"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment