You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.9 KiB

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