I’ve set up a little python script to add domains to my mailcow server, which is working fine.
I’ve got a similar one to create new mailboxes, but I can’t make it work.
It keeps returning “danger” and “mailbox_defquota_exceeds_mailbox_maxquota”

This error is incorrect, the domain is huge, and the mailbox quota tiny.

Does anyone else have this problem? Am I doing something wrong, or is it something about my server setup, or is it a bug with the API?

  • The payload looks like you want to create a mailbox, but you are calling the wrong endpoint

    url = "https://mailcow.example.com/api/v1/add/domain"

Also, I can’t add mailboxes with quota = zero, which would be ideal. Is this normal?

Have something to say?

Join the community by quickly registering to participate in this discussion. We'd like to see you joining our great moo-community!

Can you provide the API request and response?

Thanks @FreddleSpl0it ,

If I omit defquota completely, or set it to 0, I get the error message “defquota empty”.
But when I set defquota to ANY positive number, I get “mailbox_defquota_exceeds_mailbox_maxquota”

The domain is set up correctly, and I can add mailboxes manually no problem (screenshot attached showing domain, with 5GB domain quota & 5GB max quota per mailbox)

Any help would be appreciated,

Here’s my python code:

#!/usr/bin/python3
import requests
import json
from pprint import pprint
url = "https://mailcow.example.com/api/v1/add/domain"
APIKey = "my-api-key"
headers = {
	"Content-Type" :	"application/json",
	"X-API-Key" :		APIKey
}
email_local_part = "test123"
domain = "ruonline-mailer.com.au"
password = "my-password"
data = {
	"local_part": email_local_part,
	"domain": domain,
	"defquota": 1,
	"quota": 1,
	"password": password,
	"password2": password,
	"active": "1",
	"tls_enforce_in": "1",
	"tls_enforce_out": "1"
}
print("data:")
pprint(data)
r = requests.post(url, json=data, headers=headers)
print("API response:s")
pprint(r.json())

And here are some sample outputs showing the API response:

data:
{'active': '1',
 'defquota': 0,
 'domain': 'ruonline-mailer.com.au',
 'local_part': 'test123',
 'password': 'Mypassword12##',
 'password2': 'Mypassword12##',
 'quota': 0,
 'tls_enforce_in': '1',
 'tls_enforce_out': '1'}
API response:s
[{'log': ['mailbox',
          'add',
          'domain',
          {'active': '1',
           'defquota': 0,
           'domain': 'ruonline-mailer.com.au',
           'local_part': 'test123',
           'password': '*',
           'password2': '*',
           'quota': 0,
           'tls_enforce_in': '1',
           'tls_enforce_out': '1'},
          None],
  'msg': 'defquota_empty',
  'type': 'danger'}]
data:
{'active': '1',
 'defquota': 1000,
 'domain': 'ruonline-mailer.com.au',
 'local_part': 'test123',
 'password': 'Mypassword12##',
 'password2': 'Mypassword12##',
 'quota': 1000,
 'tls_enforce_in': '1',
 'tls_enforce_out': '1'}
API response:s
[{'log': ['mailbox',
          'add',
          'domain',
          {'active': '1',
           'defquota': 1000,
           'domain': 'ruonline-mailer.com.au',
           'local_part': 'test123',
           'password': '*',
           'password2': '*',
           'quota': 1000,
           'tls_enforce_in': '1',
           'tls_enforce_out': '1'},
          None],
  'msg': 'mailbox_defquota_exceeds_mailbox_maxquota',
  'type': 'danger'}]

And a screenshot showing my domain config:

The payload looks like you want to create a mailbox, but you are calling the wrong endpoint

url = "https://mailcow.example.com/api/v1/add/domain"

I created the following script to import data from a CSV file and create bulk mailbox.
It works fine but when I try to login it always says the password is wrong! Any idea?

#!/bin/bash

# Set the API key and endpoint
api_key="XXX-YYY"
api_endpoint="https://mcow.domain.tld/api/v1/add/mailbox"

# Set the CSV file path
CSV_FILE="mailboxes.csv"

# Read each line of the CSV file
while IFS=, read -r from_name user_name password; do
  # Extract the local_part and domain from the user_name
  local_part="${user_name%%@*}"
  domain="${user_name#*@}"

  # Send the API request to create the mailbox
  response=$(curl -s -X 'POST' "$api_endpoint" \
    -H 'accept: application/json' \
    -H "X-API-Key: $api_key" \
    -H 'Content-Type: application/json' \
    -d '{
      "active": "1",
      "local_part": "'"$local_part"'",
      "domain": "'"$domain"'",
      "name": "'"$from_name"'",
      "password": "'"$password"'",
      "password2": "'"$password"'",
      "quota": "0",
      "tls_enforce_in": "1",
      "tls_enforce_out": "1"
    }')

  # Check if the mailbox was created successfully
  if [[ "$response" == *"mailbox_added"* ]]; then
    echo "Mailbox created for $user_name"
  else
    echo "Error creating mailbox: $response"
  fi

done < <(tail -n +2 "$CSV_FILE")
No one is typing