Created
November 29, 2023 09:28
-
-
Save andris9/671a64af6dd82a9f9d0b8f820fff80e2 to your computer and use it in GitHub Desktop.
Example script to submit large attachments to EmailEngine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This example script submits large attachments | |
# Usage | |
# 1. Edit the variables below | |
# 2. Run the script | |
# $ bash ./submit.sh | |
## EDIT THE FOLLOWING VALUES | |
# Base URL of EmailEngine (without ending slash) | |
EMAILENGINE_URL="https://emailengine.example.com" | |
# Email account to use to submit the email | |
EMAILENGINE_ACCOUNT_ID="my-email-account" | |
# EmailEngine's Access Token | |
EMAILENGINE_TOKEN="990db3b95f8b04ab1fc64583848482605d968403f65f6b1172b678bff3b98462a" | |
# Recipient's email address | |
RECIPIENT_ADDR="[email protected]" | |
# Path to the large attachment file | |
ATTACHMENT_PATH="./example.jpeg" | |
# Set to "false" to actually deliver the email, otherwise EmailEngine will return the final EML file instead | |
DRY_RUN=true | |
# This script will generate a JSON payload to submit and stores this into the following path | |
TMPFILE_PATH="./message.json" | |
## No need to edit below | |
# generate first part of the JSON | |
echo -n '{ | |
"to": [ | |
{ | |
"address": "'${RECIPIENT_ADDR}'" | |
} | |
], | |
"subject": "Large attachment test", | |
"text": "Large attchment", | |
"attachments": [ | |
{ | |
"filename": "'$(basename $ATTACHMENT_PATH)'", | |
"content": "' > $TMPFILE_PATH | |
# add the large file as base64 string | |
openssl base64 -A -in $ATTACHMENT_PATH >> $TMPFILE_PATH | |
# add second part of the JSON | |
echo -n '", | |
"encoding": "base64" | |
} | |
], | |
"dryRun": '${DRY_RUN}' | |
}' >> $TMPFILE_PATH | |
# Submit the payload to EmailEngine | |
curl -XPOST "${EMAILENGINE_URL}/v1/account/${EMAILENGINE_ACCOUNT_ID}/submit" \ | |
-H "Authorization: Bearer ${EMAILENGINE_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
-d @${TMPFILE_PATH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment