3 #Support SENDGRID.com api
6 #SENDGRID_TO="xxxx@xxx.com"
7 #SENDGRID_FROM="xxxx@cccc.com"
12 _statusCode
="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
13 _debug
"_statusCode" "$_statusCode"
15 SENDGRID_API_KEY
="${SENDGRID_API_KEY:-$(_readaccountconf_mutable SENDGRID_API_KEY)}"
16 if [ -z "$SENDGRID_API_KEY" ]; then
18 _err
"You didn't specify a sendgrid api key SENDGRID_API_KEY yet ."
19 _err
"You can get yours from here https://sendgrid.com"
22 _saveaccountconf_mutable SENDGRID_API_KEY
"$SENDGRID_API_KEY"
24 SENDGRID_TO
="${SENDGRID_TO:-$(_readaccountconf_mutable SENDGRID_TO)}"
25 if [ -z "$SENDGRID_TO" ]; then
27 _err
"You didn't specify an email to SENDGRID_TO receive messages."
30 _saveaccountconf_mutable SENDGRID_TO
"$SENDGRID_TO"
32 SENDGRID_FROM
="${SENDGRID_FROM:-$(_readaccountconf_mutable SENDGRID_FROM)}"
33 if [ -z "$SENDGRID_FROM" ]; then
35 _err
"You didn't specify an email to SENDGRID_FROM receive messages."
38 _saveaccountconf_mutable SENDGRID_FROM
"$SENDGRID_FROM"
40 export _H1
="Authorization: Bearer $SENDGRID_API_KEY"
41 export _H2
="Content-Type: application/json"
43 _content
="$(echo "$_content" | _json_encode)"
44 _data
="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
45 response
="" #just make shellcheck happy
46 if _post
"$_data" "https://api.sendgrid.com/v3/mail/send"; then
47 if [ -z "$response" ]; then
48 _info
"sendgrid send sccess."
52 _err
"sendgrid send error."