XylotrechusZ

XylotrechusZ Shell

: /home/matican/.acme.sh/notify/ [ drwxrwxr-x ]
Uname: Linux premium72.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software: LiteSpeed
PHP version: 8.2.29 [ PHP INFO ] PHP os: Linux
Server Ip: 198.54.125.95
Your Ip: 216.73.216.35
User: matican (532) | Group: matican (531)
Safe Mode: OFF
Disable Function:
NONE

name : sendgrid.sh
#!/bin/bash

#Support SENDGRID.com api

#SENDGRID_API_KEY=""
#SENDGRID_TO="xxxx@xxx.com"
#SENDGRID_FROM="xxxx@cccc.com"

sendgrid_send() {
  _subject="$1"
  _content="$2"
  _statusCode="$3" #0: success, 1: error 2($RENEW_SKIP): skipped
  _debug "_statusCode" "$_statusCode"

  SENDGRID_API_KEY="${SENDGRID_API_KEY:-$(_readaccountconf_mutable SENDGRID_API_KEY)}"
  if [ -z "$SENDGRID_API_KEY" ]; then
    SENDGRID_API_KEY=""
    _err "You didn't specify a sendgrid api key SENDGRID_API_KEY yet ."
    _err "You can get yours from here https://sendgrid.com"
    return 1
  fi
  _saveaccountconf_mutable SENDGRID_API_KEY "$SENDGRID_API_KEY"

  SENDGRID_TO="${SENDGRID_TO:-$(_readaccountconf_mutable SENDGRID_TO)}"
  if [ -z "$SENDGRID_TO" ]; then
    SENDGRID_TO=""
    _err "You didn't specify an email to SENDGRID_TO receive messages."
    return 1
  fi
  _saveaccountconf_mutable SENDGRID_TO "$SENDGRID_TO"

  SENDGRID_FROM="${SENDGRID_FROM:-$(_readaccountconf_mutable SENDGRID_FROM)}"
  if [ -z "$SENDGRID_FROM" ]; then
    SENDGRID_FROM=""
    _err "You didn't specify an email to SENDGRID_FROM receive messages."
    return 1
  fi
  _saveaccountconf_mutable SENDGRID_FROM "$SENDGRID_FROM"

  SENDGRID_FROM_NAME="${SENDGRID_FROM_NAME:-$(_readaccountconf_mutable SENDGRID_FROM_NAME)}"
  _saveaccountconf_mutable SENDGRID_FROM_NAME "$SENDGRID_FROM_NAME"

  export _H1="Authorization: Bearer $SENDGRID_API_KEY"
  export _H2="Content-Type: application/json"

  _content="$(echo "$_content" | _json_encode)"

  if [ -z "$SENDGRID_FROM_NAME" ]; then
    _data="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
  else
    _data="{\"personalizations\": [{\"to\": [{\"email\": \"$SENDGRID_TO\"}]}],\"from\": {\"email\": \"$SENDGRID_FROM\", \"name\": \"$SENDGRID_FROM_NAME\"},\"subject\": \"$_subject\",\"content\": [{\"type\": \"text/plain\", \"value\": \"$_content\"}]}"
  fi
  response="$(_post "$_data" "https://api.sendgrid.com/v3/mail/send")"

  if [ "$?" = "0" ] && [ -z "$response" ]; then
    _info "sendgrid send sccess."
    return 0
  fi

  _err "sendgrid send error."
  _err "$response"
  return 1

}
© 2025 XylotrechusZ