]> git.proxmox.com Git - mirror_acme.sh.git/blame - notify/sendgrid.sh
Update callmebotWhatsApp.sh
[mirror_acme.sh.git] / notify / sendgrid.sh
CommitLineData
b50e701c 1#!/usr/bin/env sh
2
3#Support SENDGRID.com api
4
5#SENDGRID_API_KEY=""
6#SENDGRID_TO="xxxx@xxx.com"
7#SENDGRID_FROM="xxxx@cccc.com"
8
9sendgrid_send() {
10 _subject="$1"
11 _content="$2"
12 _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
13 _debug "_statusCode" "$_statusCode"
14
15 SENDGRID_API_KEY="${SENDGRID_API_KEY:-$(_readaccountconf_mutable SENDGRID_API_KEY)}"
16 if [ -z "$SENDGRID_API_KEY" ]; then
17 SENDGRID_API_KEY=""
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"
20 return 1
21 fi
22 _saveaccountconf_mutable SENDGRID_API_KEY "$SENDGRID_API_KEY"
23
24 SENDGRID_TO="${SENDGRID_TO:-$(_readaccountconf_mutable SENDGRID_TO)}"
25 if [ -z "$SENDGRID_TO" ]; then
26 SENDGRID_TO=""
27 _err "You didn't specify an email to SENDGRID_TO receive messages."
28 return 1
29 fi
30 _saveaccountconf_mutable SENDGRID_TO "$SENDGRID_TO"
31
32 SENDGRID_FROM="${SENDGRID_FROM:-$(_readaccountconf_mutable SENDGRID_FROM)}"
33 if [ -z "$SENDGRID_FROM" ]; then
34 SENDGRID_FROM=""
35 _err "You didn't specify an email to SENDGRID_FROM receive messages."
36 return 1
37 fi
38 _saveaccountconf_mutable SENDGRID_FROM "$SENDGRID_FROM"
39
da58fcbf
SZ
40 SENDGRID_FROM_NAME="${SENDGRID_FROM_NAME:-$(_readaccountconf_mutable SENDGRID_FROM_NAME)}"
41 _saveaccountconf_mutable SENDGRID_FROM_NAME "$SENDGRID_FROM_NAME"
42
b50e701c 43 export _H1="Authorization: Bearer $SENDGRID_API_KEY"
44 export _H2="Content-Type: application/json"
45
46 _content="$(echo "$_content" | _json_encode)"
849c3fd9 47
da58fcbf
SZ
48 if [ -z "$SENDGRID_FROM_NAME" ]; then
49 _data="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
50 else
51 _data="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\", \"name\": \"$SENDGRID_FROM_NAME\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
52 fi
143eac09 53 response="$(_post "$_data" "https://api.sendgrid.com/v3/mail/send")"
54
55 if [ "$?" = "0" ] && [ -z "$response" ]; then
56 _info "sendgrid send sccess."
57 return 0
b50e701c 58 fi
143eac09 59
b50e701c 60 _err "sendgrid send error."
61 _err "$response"
62 return 1
63
64}