-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimportusers.py
38 lines (32 loc) · 1.01 KB
/
importusers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests, csv
import base64
import getpass
#name of csv file
csvFile = 'userlist.csv'
#ask for user input
host = raw_input("MailInABox Domain: ")
host = "https://"+host
adminUser = raw_input("Admin Email: ")
adminPassword = getpass.getpass('Password:')
headers = { 'Authorization' : 'Basic %s' % base64.b64encode(adminUser+":"+adminPassword),
'Content-Type': 'application/x-www-form-urlencoded' }
#MailinaBox Endpoint
url = host+"/admin/mail/users/add"
#Open CSV File
with open('./'+csvFile) as usercsv:
rows = csv.reader(usercsv,delimiter=',')
#Set Row Counter
p=1
for row in rows:
payload = 'email='+row[0]+'&password='+row[1]
response = requests.request("POST", url, headers=headers, data = payload)
#Report to User The Result
if response.status_code != 200:
sCode = ' failed to import'
else :
sCode = ' was added successfully'
print 'Row '+str(p)+' '+str(response.text)+' '+row[0]+sCode
#Increase Counter
p += 1
#End the Script
print "\n\nEmail Import Process Completed"