]> git.proxmox.com Git - mirror_acme.sh.git/blob - notify/postmark.sh
Merge pull request #4787 from TobiasGrave/fix_variomedia_api
[mirror_acme.sh.git] / notify / postmark.sh
1 #!/usr/bin/env sh
2
3 #Support postmarkapp.com API (https://postmarkapp.com/developer/user-guide/sending-email/sending-with-api)
4
5 #POSTMARK_TOKEN=""
6 #POSTMARK_TO="xxxx@xxx.com"
7 #POSTMARK_FROM="xxxx@cccc.com"
8
9 postmark_send() {
10 _subject="$1"
11 _content="$2"
12 _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
13 _debug "_statusCode" "$_statusCode"
14
15 POSTMARK_TOKEN="${POSTMARK_TOKEN:-$(_readaccountconf_mutable POSTMARK_TOKEN)}"
16 if [ -z "$POSTMARK_TOKEN" ]; then
17 POSTMARK_TOKEN=""
18 _err "You didn't specify a POSTMARK api token POSTMARK_TOKEN yet ."
19 _err "You can get yours from here https://account.postmarkapp.com"
20 return 1
21 fi
22 _saveaccountconf_mutable POSTMARK_TOKEN "$POSTMARK_TOKEN"
23
24 POSTMARK_TO="${POSTMARK_TO:-$(_readaccountconf_mutable POSTMARK_TO)}"
25 if [ -z "$POSTMARK_TO" ]; then
26 POSTMARK_TO=""
27 _err "You didn't specify an email to POSTMARK_TO receive messages."
28 return 1
29 fi
30 _saveaccountconf_mutable POSTMARK_TO "$POSTMARK_TO"
31
32 POSTMARK_FROM="${POSTMARK_FROM:-$(_readaccountconf_mutable POSTMARK_FROM)}"
33 if [ -z "$POSTMARK_FROM" ]; then
34 POSTMARK_FROM=""
35 _err "You didn't specify an email from POSTMARK_FROM receive messages."
36 return 1
37 fi
38 _saveaccountconf_mutable POSTMARK_FROM "$POSTMARK_FROM"
39
40 export _H1="Accept: application/json"
41 export _H2="Content-Type: application/json"
42 export _H3="X-Postmark-Server-Token: $POSTMARK_TOKEN"
43
44 _content="$(echo "$_content" | _json_encode)"
45 _data="{\"To\": \"$POSTMARK_TO\", \"From\": \"$POSTMARK_FROM\", \"Subject\": \"$_subject\", \"TextBody\": \"$_content\"}"
46 if _post "$_data" "https://api.postmarkapp.com/email"; then
47 # shellcheck disable=SC2154
48 _message=$(printf "%s\n" "$response" | _lower_case | _egrep_o "\"message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \" | head -n 1)
49 if [ "$_message" = "ok" ]; then
50 _info "postmark send success."
51 return 0
52 fi
53 fi
54 _err "postmark send error."
55 _err "$response"
56 return 1
57
58 }