Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to programmatically create a mailbox for an existing user in the Active Directory by using CDOEXM


View products that this article applies to.

Introduction

This article describes how to programmatically create a mailbox for an existing user in the Active Directory directory service by using the Microsoft Collaboration Data Objects for Exchange Management (CDOEXM) interfaces.

↑ Back to the top


More information

Some customers have encountered problems with the CreateMailbox function when they try to create mailboxes for existing users in Active Directory. These problems occur on servers that are running either Exchange 2000 Server or Exchange Server 2003. When they try to create mailboxes, they receive one of the following error messages:
Error -2147467259 There is no Connection Agreement configured to export this recipient to the Exchange 5.5 server.
ID no: c1034a1b Microsoft CDO for Exchange Management
Error -2147016646 The server is not operational Facility: Win32
ID no: 8007203a Microsoft CDO for Exchange Management
These customers have been able to work around this problem by binding explicitly to a domain controller.

Sample code

The following Microsoft VBScript sample code shows how to programmatically create a mailbox for an existing user by using CDOEXM. You must run this sample code on a computer that has the Microsoft Exchange System Manager Tools installed.
  1. Create a domain user. However, do not create an Exchange mailbox for the domain user.
  2. Create a .vbs file
  3. Add the following sample code to the .vbs file.
    Dim oIADSUser
    Dim oMailbox
    
    Set oIADS = GetObject("LDAP://RootDSE")
    strDefaultNC = oIADS.Get("defaultnamingcontext")
    'MsgBox FindAnyMDB("CN=Configuration," & strDefaultNC)
    
    'TODO: Use the newly created domain user account to replace the "UserName". 
    Set oIADSUser = GetObject("LDAP://CN=UserName,CN=Users," & strDefaultNC)
    
    If oIADSUser Is Nothing then
    	MsgBox "The oIADSUser is Nothing."
    Else
    	MsgBox "The oIADSUser is created successfully."
    End If
    
    Set oMailBox = oIADSUser
    oMailbox.CreateMailbox FindAnyMDB("CN=Configuration," & strDefaultNC)
    oIADSUser.SetInfo
    
    Function FindAnyMDB(strConfigurationNC)
    	Dim oConnection 
    	Dim oCommand 
    	Dim oRecordSet 
    	Dim strQuery 
    
    	' Open the Connection.
    	Set oConnection = CreateObject("ADODB.Connection")
    	set oCommand = CreateObject("ADODB.Command")
    	Set oRecordSet = CreateObject("ADODB.Recordset")
    
    	oConnection.Provider = "ADsDSOObject"
    	oConnection.Open "ADs Provider"
    
    	' Build the query to find the private MDB.
    	strQuery = "<LDAP://" & strConfigurationNC & ">;(objectCategory=msExchPrivateMDB);name,adspath;subtree"
    
    	oCommand.ActiveConnection = oConnection
    	oCommand.CommandText = strQuery
    	Set oRecordSet = oCommand.Execute
    
    	' If you have an MDB, return the first one.
    	If Not oRecordSet.EOF Then
    		oRecordSet.MoveFirst
    		FindAnyMDB = CStr(oRecordSet.Fields("ADsPath").Value)
    	Else
    		FindAnyMDB = ""
    	End If
    
    
    	'Clean up.
    	oRecordSet.Close
    	oConnection.Close
    	Set oRecordSet = Nothing
    	Set oCommand = Nothing
    	Set oConnection = Nothing
    End Function
    
  4. Search for the TODO text string in the code, and then modify the code for your environment.
  5. Run the sample code.

↑ Back to the top


References

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
313114 How to create a mailbox-enabled recipient by using C# .NET
304935 How to set Exchange 2000 mailbox rights at the time of mailbox creation
For additional information about CDOEXM, visit the following Microsoft Developer Network (MSDN) Web site:For additional information about the CreateMailBox method, visit the following MSDN Web site:For additional information about CDOEXM, see the "CDOEXM" topic in the Microsoft Exchange 2000 Server software development kit (SDK).

↑ Back to the top


Keywords: KB327079, kbhowto

↑ Back to the top

Article Info
Article ID : 327079
Revision : 6
Created on : 10/25/2007
Published on : 10/25/2007
Exists online : False
Views : 343