Last active
April 30, 2023 01:10
-
-
Save amanjuman/28f8117056cd6b4d93c5a6d50564dc83 to your computer and use it in GitHub Desktop.
MailCow Import Multiple Mailbox from CSV File
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
#!/bin/bash | |
# Set the API endpoint URL and key | |
ENDPOINT="https://mcow.domain.tld/api/v1/add/mailbox" | |
API_KEY="XXX-YYY" | |
# Read the CSV file line by line and create mailbox users | |
while IFS=',' read -r from_name from_email user_name password; do | |
# Extract the domain from the user_name field | |
domain=$(echo "$user_name" | awk -F'@' '{print $2}') | |
# Extract the local part from the user_name field | |
local_part=$(echo "$user_name" | awk -F'@' '{print $1}') | |
# Build the API request JSON | |
data=$(cat <<EOF | |
{ | |
"active": "1", | |
"domain": "$domain", | |
"local_part": "$local_part", | |
"name": "$from_name", | |
"password": "$password", | |
"password2": "$password", | |
"quota": "0", | |
"tls_enforce_in": "1", | |
"tls_enforce_out": "1" | |
} | |
EOF | |
) | |
# Make the API request | |
response=$(curl -s -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" -d "$data" "$ENDPOINT") | |
# Print the response | |
echo "Response for $user_name:" | |
echo "$response" | |
done < <(tail -n +2 /root/mailboxes.csv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment