#!/usr/bin/env bash # # SendPier Send API — send a stored template. # # Requirements: bash and curl. # # Usage: # export SENDPIER_API_KEY='sp_live_...' # export SENDPIER_DOMAIN='example.com' # export SENDPIER_FROM='orders@example.com' # ./send-with-template.sh recipient@example.org 7 # # The template itself lives in the control panel; the request only carries its # id and the variables. Sending a template is the safer route whenever the # values come from your own users: template values are inserted as text, so # they cannot break your HTML open. set -euo pipefail API_BASE='https://api.sendpier.com' : "${SENDPIER_API_KEY:?set SENDPIER_API_KEY to your Send API key}" : "${SENDPIER_DOMAIN:?set SENDPIER_DOMAIN to the domain the key belongs to}" : "${SENDPIER_FROM:?set SENDPIER_FROM to a sender address on that domain}" recipient="${1:-}" template_id="${2:-}" if [ -z "$recipient" ] || [ -z "$template_id" ]; then echo "usage: $0 " >&2 exit 64 fi # Send every variable the template uses. Miss one and the whole request is # refused with 422 missing_template_variables, naming the fields you forgot -- # so nobody receives a half-filled message. # # "html" or "text" next to a template_id is refused (422 template_body_conflict); # the body comes from the template. Your own "subject" is allowed and wins. body=$(cat <&2 exit 1 fi echo "accepted (HTTP 202)" >&2