Created
January 25, 2021 16:30
-
-
Save broland07/acd1ed48821335d4de81fa1daf047543 to your computer and use it in GitHub Desktop.
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 | |
# Email setup | |
SENDGRID_API_KEY="SG.xxxxxx" | |
FILENAME_ATTACH="bash test file" | |
FILENAME_ZIP="test.txt" | |
FILENAME_BASE64_TMP="test.txt" | |
EMAIL_TO="[email protected]" | |
EMAIL_SUBJECT="test bash file" | |
EMAIL_FROM="[email protected]" | |
EMAIL_MESSAGE="test bash file" | |
function email_exports() | |
{ | |
FILENAME_BASE64=$(base64 -w0 $FILENAME_ZIP); | |
REQUEST_DATA='{"personalizations": [{ | |
"to": [{ "email": "'"$EMAIL_TO"'" }], | |
"subject": "'"$EMAIL_SUBJECT"'" | |
}], | |
"from": { | |
"email": "'"$EMAIL_FROM"'" | |
}, | |
"content": [{ | |
"type": "text/plain", | |
"value": "'"$EMAIL_MESSAGE"'" | |
}], | |
"attachments": [{ | |
"content": "'"$FILENAME_BASE64"'", | |
"filename": "'"$FILENAME_ATTACH"'" | |
}] | |
}'; | |
# We need to store the base64 locally as the text | |
# is too big for sending directly with curl | |
echo $REQUEST_DATA > $FILENAME_BASE64_TMP | |
curl -X "POST" "https://api.sendgrid.com/v3/mail/send" \ | |
-H "Authorization: Bearer $SENDGRID_API_KEY" \ | |
-H "Content-Type: application/json" \ | |
-d "@$FILENAME_BASE64_TMP"; | |
rm $FILENAME_BASE64_TMP | |
} | |
email_exports |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment