-
-
Save kyanny/cebfc3c6be184c422718 to your computer and use it in GitHub Desktop.
Delete email address from suppression list of SendGrid
This file contains 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
export API_USER=your_sendgrid_username | |
export API_KEY=your_sendgrid_password | |
export EMAIL=foo@example.com | |
export RED='\033[0;31m' | |
export GREEN='\033[0;32m' | |
export NC='\033[0m' # No Color | |
curl -X GET "https://api.sendgrid.com/api/bounces.get.json?api_user=${API_USER}&api_key=${API_KEY}&email=${EMAIL}" > bounces.json | |
count=$(ruby -rjson -e "print JSON.parse(File.read(%Q,bounces.json,)).length") | |
if [ 0 -eq $count ] | |
then | |
echo -e "${GREEN}${EMAIL} is not in the list.${NC}" | |
else | |
curl -X POST https://api.sendgrid.com/api/bounces.delete.json -d api_user=$API_USER -d api_key=$API_KEY -d email=$EMAIL > results.json | |
count=$(grep -c 'success' results.json) | |
if [ 1 -eq $count ] | |
then | |
echo -e "${GREEN}${EMAIL} is deleted from the list.${NC}" | |
else | |
echo -e "${RED}Can't delete ${EMAIL} from the list.${NC}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment