33 lines
863 B
Python
Executable File
33 lines
863 B
Python
Executable File
#!/bin/python3
|
|
|
|
import csv
|
|
import requests
|
|
|
|
api_url = "https://your mailcow domain here/api/v1/add/mailbox"
|
|
|
|
# Your API key
|
|
api_key = "API Key here"
|
|
|
|
with open('mailboxes.csv', newline='') as csvfile:
|
|
reader = csv.DictReader(csvfile)
|
|
for row in reader:
|
|
data = {
|
|
'local_part': row['username'],
|
|
'domain': row['domain'],
|
|
'password': row['password'],
|
|
'name': row['name'],
|
|
'quota': row['quota']
|
|
}
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json',
|
|
'X-API-Key': api_key
|
|
}
|
|
response = requests.post(api_url, headers=headers, json=data)
|
|
|
|
if response.status_code == 200:
|
|
print(f"{row['username']}@{row['domain']} successful")
|
|
else:
|
|
print(f"ERROR {row['username']}@{row['domain']}: {response.content}")
|
|
|