I am new to Python and, in fact, I have limited programming experience in general.
I am attempting to create a web form that our HR employees can use to add new employees into Active Directory and to create a mailbox for that user. AD is on a WIN2k server and Exchange 2000. I have the form and some code that will add the user based on submitted fields from the webform. The code fails when it gets to the part about creating the mailbox. Below is my code:
import win32com.client
import win32com, win32com.adsi
import pythoncom
import cgi
FormFile = "addusertmp.html"
print 'Content-Type: text/html\n\n'
def DisplayForm():
FormHandle = open(FormFile, "r")
FormInput = FormHandle.read()
FormHandle.close()
print FormInput
def ProcessForm(entries):
first = entries['first'].value
last = entries['last'].value
login = entries['login'].value
password = entries['password'].value
title = entries['title'].value
entries = cgi.FieldStorage()
def add_acct (location, user):
ad_obj=win32com.client.GetObject(location)
ad_user=ad_obj.Create('user','cn='+user['login'])
ad_user.Put('sAMAccountName',user['login'])
ad_user.Put('userPrincipalName',user['login']+'@domain.org')
ad_user.Put('DisplayName',user['first']+' '+user['last'])
ad_user.Put('givenName',user['first'])
ad_user.Put('sn',user['last'])
ad_user.Put('description',user['title'])
ad_user.SetInfo();ad_user.GetInfo()
ad_user.AccountDisabled=0
ad_user.setpassword(user['password'])
ad_user.SetInfo()
ad_user.CreateMailbox('CN=Maibox Store (SERVER),CN=First Storage Group,CN=InformationStore,CN=SERVER,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Company Name,CN=Microsoft Exchange,CN=Services,CN=Configuration'+location)
ad_user.EmailAddress=user+'@domain.org'
ad_user.SetInfo()
ad_user.Put('msExchUserAccountControl',2)
ad_user.SetInfo()
if entries:
location='LDAP://OU=Employees,DC=domain,DC=org'
user={'first':entries.getvalue('first'),'last':entries.getvalue('last'),'login':entries.getvalue('login'),'title':entries.getvalue('title'),'password':entries.getvalue('password')}
print user
add_acct(location,user)
print "user added"
else:
DisplayForm()
When I go to the web form and I enter&submit the required fields, this creates the user & enables the user, but also produces the following error and never creates the mailbox:
{'password': 'test', 'login': 'bbonez', 'title': 'Bouncer', 'last': 'Bonez', 'first': 'Big'} Traceback (most recent call last): File "W:\SysadminSite\adduser2.cgp", line 50, in ? add_acct(location,user) File "W:\SysadminSite\adduser2.cgp", line 37, in add_acct ad_user.CreateMailbox('CN=Maibox Store (SERVER),CN=First Storage Group,CN=InformationStore,CN=SERVER,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=Company Name,CN=Microsoft Exchange,CN=Services,CN=Configuration'+location) File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 438, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: .CreateMailbox
Any help would be GREATLY appreciated. Thank you!