#!/usr/bin/env bash
# Send an email synchronously
set -u
: "${MAILCHANNELS_API_KEY:?Set MAILCHANNELS_API_KEY before running}"
: "${FROM_EMAIL:?Set FROM_EMAIL (must be on a Domain-Lockdown-authorized domain)}"
: "${TO_EMAIL:?Set TO_EMAIL}"
curl -X POST https://api.mailchannels.net/tx/v1/send \
-H "Content-Type: application/json" \
-H "X-Api-Key: $MAILCHANNELS_API_KEY" \
-d @- <<JSON
{
"personalizations": [
{ "to": [{ "email": "$TO_EMAIL", "name": "Recipient" }] }
],
"from": {
"email": "$FROM_EMAIL",
"name": "Your Name"
},
"subject": "Hello from MailChannels (sync)",
"content": [
{
"type": "text/plain",
"value": "This message was sent with POST /tx/v1/send. The caller waited for the response."
}
]
}
JSON