469,943 Members | 2,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,943 developers. It's quick & easy.

C# Exchange create mailbox

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
Mar 20 '07 #1
2 8885
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" <ar*******@discussions.microsoft.comwrote in message
news:D8**********************************@microsof t.com...
>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

Mar 21 '07 #2
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" wrote:
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" <ar*******@discussions.microsoft.comwrote in message
news:D8**********************************@microsof t.com...
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


Mar 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Manuel Krummenacher | last post: by
reply views Thread by Gabe Matteson | last post: by
reply views Thread by Tim Sapp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.