C# Exchange create mailbox

G

Guest

I have the following code that creates a user and makes a mailbox with it:
private void kandidaatAanmaken(string voornaam, string achternaam, string
gebruikersnaam)
{
string password = "1234567";
DirectoryEntry container, user;
string homeMDB = "";

container = new DirectoryEntry("LDAP://192.168.0.56/CN=Users,
DC=aoicttest, DC=local");
user = container.Children.Add("cn="+voornaam+" "+achternaam, "user");
user.Properties["sAMAccountName"].Add(gebruikersnaam);
user.CommitChanges();
user.Invoke("SetPassword", new object[]{password});
user.Properties["UserAccountControl"].Value = 0x200;
user.CommitChanges();

//Group(wenskandidaten) opzoeken en de kandidaat aan de group
toevoegen
DirectoryEntry groupDE = new DirectoryEntry();
groupDE.Username = "administrator";
groupDE.Password = "1234567";
groupDE.Path = container.Path;
DirectoryEntry groupEntry =
groupDE.Children.Find("CN=wenskandidaten", "group");
groupEntry.Invoke("add", new object[] {user.Path});

CDOEXM.IMailboxStore mailbox;
homeMDB = "CN=Mailbox Store(aoicttestserver), CN=First Storage Group,"
+ "CN=InformationStore, CN=aoicttestserver, CN=Servers,"
+ "CN=First Administrative Group, CN=Administrative Groups,"
+ "CN=aoicttest ,CN=Microsoft Exchange, CN=Services,"
+ "CN=Configuration, DC=aoicttest, DC=local";
mailbox = (IMailboxStore)user.NativeObject;
mailbox.CreateMailbox(homeMDB);
user.CommitChanges();
}

Now, the creation of the user goes allright, but the creation of the mailbox
goes wrong. I have the following computername and domainname:
computername(full): aoicttestserver.aoicttest.local
domain: aoicttest.local

Please help me with this problem.

Arjen
 
R

Richard T. Edwards

Does this happen if you seperate the two fuctions as two different programs?

I ask this because I have seen this before with Intel and the issue was the
same.

Once you create an object, the entire program runs under the credentials of
that account.

When you make the second call, if your credentials are not in harmony with
the permissions
needed to perform the second call, it fails.

Also, it may be that LDAP hasn't been given enough time to allow for updates
and isn't seeing it.

hth


..
 
G

Guest

I have seen you posted a reply on my problem. Unfortunately, this did not
solve it. When I place it in a file of its own, I still get the same error:
Value does not fall within the expected range.
Can you please give me some more tips?

Richard T. Edwards said:
Does this happen if you seperate the two fuctions as two different programs?

I ask this because I have seen this before with Intel and the issue was the
same.

Once you create an object, the entire program runs under the credentials of
that account.

When you make the second call, if your credentials are not in harmony with
the permissions
needed to perform the second call, it fails.

Also, it may be that LDAP hasn't been given enough time to allow for updates
and isn't seeing it.

hth


..
arjen1984 said:
I have the following code that creates a user and makes a mailbox with it:
private void kandidaatAanmaken(string voornaam, string achternaam, string
gebruikersnaam)
{
string password = "1234567";
DirectoryEntry container, user;
string homeMDB = "";

container = new DirectoryEntry("LDAP://192.168.0.56/CN=Users,
DC=aoicttest, DC=local");
user = container.Children.Add("cn="+voornaam+" "+achternaam,
"user");
user.Properties["sAMAccountName"].Add(gebruikersnaam);
user.CommitChanges();
user.Invoke("SetPassword", new object[]{password});
user.Properties["UserAccountControl"].Value = 0x200;
user.CommitChanges();

//Group(wenskandidaten) opzoeken en de kandidaat aan de group
toevoegen
DirectoryEntry groupDE = new DirectoryEntry();
groupDE.Username = "administrator";
groupDE.Password = "1234567";
groupDE.Path = container.Path;
DirectoryEntry groupEntry =
groupDE.Children.Find("CN=wenskandidaten", "group");
groupEntry.Invoke("add", new object[] {user.Path});

CDOEXM.IMailboxStore mailbox;
homeMDB = "CN=Mailbox Store(aoicttestserver), CN=First Storage
Group,"
+ "CN=InformationStore, CN=aoicttestserver, CN=Servers,"
+ "CN=First Administrative Group, CN=Administrative
Groups,"
+ "CN=aoicttest ,CN=Microsoft Exchange, CN=Services,"
+ "CN=Configuration, DC=aoicttest, DC=local";
mailbox = (IMailboxStore)user.NativeObject;
mailbox.CreateMailbox(homeMDB);
user.CommitChanges();
}

Now, the creation of the user goes allright, but the creation of the
mailbox
goes wrong. I have the following computername and domainname:
computername(full): aoicttestserver.aoicttest.local
domain: aoicttest.local

Please help me with this problem.

Arjen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top