/
/
Bulk creation of mailboxes

Bulk creation of mailboxes

Important!

All actions must be performed under an administrator account, the domains of the mailboxes being created must be set up in advance.

Bulk mailbox creation is possible with bash script. Create a file called massboxes.sh and paste the following contents in it:

#!/bin/bash

# Path to CSV file
CSV_FILE="mailboxes.csv"

# Checking file existence
if [[ ! -f "$CSV_FILE" ]]; then
  echo "File $CSV_FILE not found!"
  exit 1
fi

echo "Starting to create mailboxes from $CSV_FILE..."

# Read CSV line by line, skipping the header
tail -n +2 "$CSV_FILE" | while IFS=',' read -r name domain passwd; do

  # Skip empty lines
  [[ -z "$name" || -z "$domain" || -z "$passwd" ]] && continue

  echo "Creating mailbox: $name@$domain"

  /usr/local/mgr5/sbin/mgrctl -m ispmgr email.edit \
    domainname="$domain" \
    name="$name" \
    passwd="$passwd" \
    confirm="$passwd" \
    plid="$domain" \
    aliases='' \
    sok=ok

  if [ $? -eq 0 ]; then
    echo "Success: $name@$domain"
  else
    echo "Error during creation: $name@$domain"
  fi

  echo "---"

done

echo "All mailboxes have been processed."

Make the file an executable:

chmod +x massboxes.sh

Then, in the same directory where the bash script is, create or upload a CSV file mailboxes.csv with a list of mailboxes in the format Name, Domain, Password. For example:

info,exmaple.com,qwerty1234
admin,example.com,q1w2e3r4t5
no-reply,domain.com,passwd123
webmaster,domain.com,123passwd456

Run the script:

./massboxes.sh