Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Created April 28, 2023 21:29
Show Gist options
  • Save amanjuman/cea0445f11e24c99fae8e552d87b5067 to your computer and use it in GitHub Desktop.
Save amanjuman/cea0445f11e24c99fae8e552d87b5067 to your computer and use it in GitHub Desktop.
MailCow Add Multiple Domain from a text file using API
#!/bin/bash
# Set your Mailcow API key and endpoint
api_key="xxx-xxx-xxxx"
api_endpoint="https://mcow.example.ltd/api/v1/add/domain"
# Set default domain values
aliases="400"
mailboxes="100"
defquota="1024"
maxquota="5120"
quota="512000"
relay_unknown_only="1"
gal="1"
active="1"
# Read domain names from file and add to Mailcow
while read -r domain; do
# Send POST request to add domain to Mailcow
curl -sSf -X 'POST' \
"$api_endpoint" \
-H 'accept: application/json' \
-H "X-API-Key: $api_key" \
-H 'Content-Type: application/json' \
-d "{
\"domain\": \"$domain\",
\"aliases\": \"$aliases\",
\"mailboxes\": \"$mailboxes\",
\"defquota\": \"$defquota\",
\"maxquota\": \"$maxquota\",
\"quota\": \"$quota\",
\"relay_unknown_only\": \"$relay_unknown_only\",
\"gal\": \"$gal\",
\"active\": \"$active\"
}"
echo "Added domain: $domain"
done < domains.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment