Create multiple inboxes at one time

using this code here, is it possible to put the details of 1-100 email inboxes all at once, instead of putting the details of each one manually

thanks!

Yes, you’ll need to create a file with the usernames and passwords of the accounts, then have a script ran against the file to create the accounts.

Remember that you also need to authenticate as a part of the curl request.

I asked Claude for some guidance. A bit more elaborate than I would have made it, but good anyways. :slight_smile:

Here’s the updated script using box.example.com as the domain and accounting for the success message format:

#!/bin/bash

# Admin credentials
ADMIN_EMAIL="admin@example.com"
ADMIN_PASSWORD="your_admin_password"
API_URL="https://box.example.com/admin/mail/users/add"

# Input file containing email addresses (one per line)
INPUT_FILE="email_list.txt"

# Check if input file exists
if [ ! -f "$INPUT_FILE" ]; then
  echo "Error: Input file '$INPUT_FILE' not found."
  exit 1
fi

# Generate a random password
generate_password() {
  # Generate a 12-character password with letters, numbers, and symbols
  chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+"
  password=""
  for i in {1..12}; do
    random_index=$((RANDOM % ${#chars}))
    password="${password}${chars:$random_index:1}"
  done
  echo "$password"
}

# Create a log file to store created accounts and passwords
LOG_FILE="created_users_$(date +%Y%m%d_%H%M%S).csv"
echo "Email,Password,Status" > "$LOG_FILE"

# Read each email from the input file and create the user
while IFS= read -r EMAIL || [ -n "$EMAIL" ]; do
  # Skip empty lines
  if [ -z "$EMAIL" ]; then
    continue
  fi
  
  # Generate a random password for this user
  PASSWORD=$(generate_password)
  
  echo "Creating user: $EMAIL"
  
  # Make the API call to create the user - using separate -d parameters
  RESPONSE=$(curl -s -X POST \
    -d "email=$EMAIL" \
    -d "password=$PASSWORD" \
    --user "$ADMIN_EMAIL:$ADMIN_PASSWORD" \
    "$API_URL")
  
  # Check if the creation was successful based on exact success message
  if [[ "$RESPONSE" == "mail user added" ]]; then
    STATUS="Success"
  else
    STATUS="Failed: $RESPONSE"
  fi
  
  # Log the created user
  echo "$EMAIL,$PASSWORD,$STATUS" >> "$LOG_FILE"
  
  # Add a small delay to avoid overwhelming the server
  sleep 1
done < "$INPUT_FILE"

echo "User creation completed. Results saved to $LOG_FILE"

Key updates in this script:

  1. Domain changed to box.example.com
  2. The success check now looks specifically for the exact message “mail user added” instead of a generic check
  3. Using separate -d parameters for email and password as shown in your working example

To use this script:

  1. Create a text file named email_list.txt with one email address per line
  2. Update the ADMIN_EMAIL and ADMIN_PASSWORD with your actual admin credentials
  3. Run the script to create all users and generate a CSV with their passwords
2 Likes

wow thats amazing! i will have to try figure this out and test it tomorrow thank you!

STOP!!! @DanteN

The script looked wrong, so I tested it… I will add the corrected script momentarily.

I only tested the formatting of the API call, not the entire script. Let me know how it works out. :slight_smile:

no problem! i take it the script was edited above?

Yes, indeed. @DanteN