Using Bash and jq to Validate and Block Disposable Emails
This document provides example code for how to use Bash with curl
and jq
to validate an email and determine if it is from a disposable email provider using the Check-Mail API.
Prerequisites
- An active Check-Mail API account.
- Your API key.
curl
andjq
installed on your machine.
Example Bash Script
The following script uses curl
to make an API request and jq
to parse the JSON response.
#!/bin/bash
API_KEY="YOUR_API_KEY"
EMAIL="vataya4620@ruhtan.com"
# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "Error: jq is not installed. Please install jq to run this script."
exit 1
fi
# Make the API request
RESPONSE=$(curl -s -X GET "https://api.check-mail.org/v1/?email=${EMAIL}" \
-H "Authorization: Bearer ${API_KEY}"
# Parse the response using jq
VALID=$(echo $RESPONSE | jq '.valid')
BLOCK=$(echo $RESPONSE | jq '.block')
DISPOSABLE=$(echo $RESPONSE | jq '.disposable')
RISK=$(echo $RESPONSE | jq '.risk')
# Output the response
echo "Email: ${EMAIL}"
echo "Valid: $( [ "$VALID" = true ] && echo "Yes" || echo "No" )"
echo "Block: $( [ "$BLOCK" = true ] && echo "Yes" || echo "No" )"
echo "Disposable: $( [ "$DISPOSABLE" = true ] && echo "Yes" || echo "No" )"
echo "Risk Score: ${RISK}"
Replace YOUR_API_KEY
with your actual API key and vataya4620@ruhtan.com
with the email address you want to validate.
Explanation
- The script uses
curl
to send aGET
request to the Check-Mail API. - The response is then parsed using
jq
to extract the relevant fields (valid
,block
,disposable
,risk
). - If
jq
is not installed, the script will show an error message and exit.
Next Steps
- Integrate this Bash script into your automation workflow to detect disposable email addresses.
- Refer to the documentation for further details on the API.