How to create a mailbox account for an existing user.

How to create a mailbox account for an existing user.

Post by Phanidha » Tue, 08 Jul 2003 16:17:40



Hi,
Quote:> I'm using ADS as my user data store. I'm creating users
>in ADS using a thrid party software. But this software
>does not take care of creating a mailbox for the user in
>the exchange server. My ADS and Exchange server 2000
>reside on the same machine.
>  I'm writng a .NET application in C# to create a mailbox
>account.But When I run the application I get the

exception "System.Runtime.InterOpSrvices.COMException
(0x80072030).There is no such object on the server".I'm
using CDOEXM for exchange management.Here's
Quote:>how my code looks.

><C#CODE>

>string user = "mailenableduser";
>//get the user name
>DirectoryEntry container, user;
>container = new DirectoryEntry
>("LDAP://cn=users,dc=fa,dc=com");

>//form the LDAP filter
>string strldapFilter = String.Format("(samAccountName=
>{0})",user);

>//Search the directory
>DirectorySearcher searcher = new DirectorySearcher
>(strldapFilter);

>string strmdbURL = String.Format("LDAP://{0}/CN=Mailbox
>Store({0}),CN=First Storage Group,CN=InformationStore,CN=
>{0},CN=Servers,CN=First Administrative
>Group,CN=Administrative Groups,CN=First
>Organization,CN=Microsoft
>Exchange,CN=Services,CN=Configuration,DC=fa,DC=com","myser
v
>er");

>SearchResult searchResult = searcher.FindOne();

>if(searchResult == null)
> MessageBox.Show("There is no user by that name");
>else
>MessageBox.Show("The user is a valid user and an attempt
>is being made to create a mail box for him");

>//convert this search result to a Directory entry
>user = searchResult.GetDirectoryEntry();

>//create mailbox for the user using CDOEXM calls
>CDOEXM.IMailboxStore exchangeMailbox =
>(CDOEXM.IMailboxStore)user.NativeObject;

>exchangeMailbox.CreateMailbox(strmdbURL);
>user.CommitChanges();

></C#CODE>

>  I've seen someone complaining that there is some
problem
>while craeting a mailbox from C#.NET. So I tried to do it
>from VB.NET.Here's how my VB function, which handles
>creating the mailbox for the user, look like

><VBCODE>

>Function CreateCDOEXMailBox(ByVal ADSIUserPath As String,
>ByVal DCServer As String, ByVal DomainName As String) As
>Boolean

>        Dim objMailbox As CDOEXM.IMailboxStore
>        Dim objADSIuser As ActiveDs.IADsUser

>        Try
>            'Bind User to AD
>            objADSIuser = GetObject(ADSIUserPath)

>            objMailbox = objADSIuser

>            objMailbox.CreateMailbox("LDAP://" & DCServer
>& "/" & _
>            "CN=Mailbox Store (" & DCServer & ")," & _
>            "CN=First Storage Group," & _
>            "CN=InformationStore," & _
>            "CN=" & DCServer & "," & _
>            "CN=Servers," & _
>            "CN=First Administrative Group," & _
>            "CN=Administrative Groups," & _
>            "CN=First Organization," & _
>            "CN=Microsoft Exchange," & _
>            "CN=Services," & _
>            "CN=Configuration," & DomainName)

>            objADSIuser.SetInfo()
>            Return True
>        Catch exceptionEX As System.Exception
>            Throw exceptionEX
>        End Try
>    End Function
> <VBCODE>

> Here i get an exception "Cannot create ActiveX
component"
>while calling 'GetObject'.

>  Any help in resolving this issue will be appreciated.
> Thanking you in advance.
>Regards
>Phanidhar

 
 
 

How to create a mailbox account for an existing user.

Post by Siegfried Weber [MVP » Thu, 10 Jul 2003 09:12:45


The erorr you receive usually points to a malformed URL in the
.CreateMailbox method. I am not sure if "LDAP://{0}/" is really valid. You'd
probably need to remove that and replace it with "LDAP://Mailbox Store"etc.

--
<Cheers:Siegfried runat="server" />

Development Lead,

CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
http://www.cdolive.com

This information is provided "AS IS" with no warranties, and confers no
rights.
You assume all risk for your use. ? 2003 CDOLive LLC. All rights reserved.
Sample code subject to http://www.cdolive.com/disclaim.htm


> Hi,
>> I'm using ADS as my user data store. I'm creating users
>> in ADS using a thrid party software. But this software
>> does not take care of creating a mailbox for the user in
>> the exchange server. My ADS and Exchange server 2000
>> reside on the same machine.
>>  I'm writng a .NET application in C# to create a mailbox
>> account.But When I run the application I get the
> exception "System.Runtime.InterOpSrvices.COMException
> (0x80072030).There is no such object on the server".I'm
> using CDOEXM for exchange management.Here's
>> how my code looks.

>> <C#CODE>

>> string user = "mailenableduser";
>> //get the user name
>> DirectoryEntry container, user;
>> container = new DirectoryEntry
>> ("LDAP://cn=users,dc=fa,dc=com");

>> //form the LDAP filter
>> string strldapFilter = String.Format("(samAccountName=
>> {0})",user);

>> //Search the directory
>> DirectorySearcher searcher = new DirectorySearcher
>> (strldapFilter);

>> string strmdbURL = String.Format("LDAP://{0}/CN=Mailbox
>> Store({0}),CN=First Storage Group,CN=InformationStore,CN=
>> {0},CN=Servers,CN=First Administrative
>> Group,CN=Administrative Groups,CN=First
>> Organization,CN=Microsoft
>> Exchange,CN=Services,CN=Configuration,DC=fa,DC=com","myser v
>> er");

>> SearchResult searchResult = searcher.FindOne();

>> if(searchResult == null)
>> MessageBox.Show("There is no user by that name");
>> else
>> MessageBox.Show("The user is a valid user and an attempt
>> is being made to create a mail box for him");

>> //convert this search result to a Directory entry
>> user = searchResult.GetDirectoryEntry();

>> //create mailbox for the user using CDOEXM calls
>> CDOEXM.IMailboxStore exchangeMailbox =
>> (CDOEXM.IMailboxStore)user.NativeObject;

>> exchangeMailbox.CreateMailbox(strmdbURL);
>> user.CommitChanges();

>> </C#CODE>

>>  I've seen someone complaining that there is some problem
>> while craeting a mailbox from C#.NET. So I tried to do it
>> from VB.NET.Here's how my VB function, which handles
>> creating the mailbox for the user, look like

>> <VBCODE>

>> Function CreateCDOEXMailBox(ByVal ADSIUserPath As String,
>> ByVal DCServer As String, ByVal DomainName As String) As
>> Boolean

>>        Dim objMailbox As CDOEXM.IMailboxStore
>>        Dim objADSIuser As ActiveDs.IADsUser

>>        Try
>>            'Bind User to AD
>>            objADSIuser = GetObject(ADSIUserPath)

>>            objMailbox = objADSIuser

>>            objMailbox.CreateMailbox("LDAP://" & DCServer
>> & "/" & _
>>            "CN=Mailbox Store (" & DCServer & ")," & _
>>            "CN=First Storage Group," & _
>>            "CN=InformationStore," & _
>>            "CN=" & DCServer & "," & _
>>            "CN=Servers," & _
>>            "CN=First Administrative Group," & _
>>            "CN=Administrative Groups," & _
>>            "CN=First Organization," & _
>>            "CN=Microsoft Exchange," & _
>>            "CN=Services," & _
>>            "CN=Configuration," & DomainName)

>>            objADSIuser.SetInfo()
>>            Return True
>>        Catch exceptionEX As System.Exception
>>            Throw exceptionEX
>>        End Try
>>    End Function
>> <VBCODE>

>> Here i get an exception "Cannot create ActiveX component"
>> while calling 'GetObject'.

>>  Any help in resolving this issue will be appreciated.
>> Thanking you in advance.
>> Regards
>> Phanidhar