Thanks to your suggestions I got one step beyond!!
But it is not over yet! ;)
Now I get an "System.ArgumentException: The parameter is incorrect."
at the line
objMailbox.CreateMailbox(HomeMDBURL)
I believe my CDOEXM Installation is correct cause:
-I have no more my System.InvalidCastException at the previous line.
-The VisualBasic equivalent code DO run on my machine!!!
-Also, I checked the LDAP String for the argument of CreateMailbox()
with a LDAP Browser:
I browsed my Active Directory from root and CN=Services,CN=Microsoft
Exchange and so on to the final Entry "MailBox Store (MYSERVER)" and
then I copied and pasted it in order to build the HomeMDBURL String.
So I am pretty sure there's no typing error in it...
So what is wrong now??
Isn't the String too long?
Here's my code again: Don't look at the mess.. The code is far from
being optimized...
<CODE>
public bool addUserWithMailBox(String fullName, String sLogin, String
sPassword, String sEMailBox)
{
string emailname = sEMailBox;
string LastName = fullName;
string FirstName = fullName;
string DomainName = "DC=my,DC=domain,DC=com";
string ServerName="Myserver";
string strMDB="MailBox Store (MYSERVER)";
IADsUser objUser;
IADsContainer objContainer;
CDOEXM.IMailboxStore objMailbox;
string recip;
recip = "CN=" + emailname;
//Récupération du container
DirectoryEntry oEntry = new DirectoryEntry("LDAP://" + ServerName +
"/" +
"CN=users," + DomainName);
oEntry.Username = "cn=Administrator,cn=Users,dc=my,dc=domain,dc=com";
oEntry.Password = "admin";
DirectoryEntry newUser = oEntry.Children.Add("CN=" + sLogin ,"user");
newUser.Properties["sAMAccountName"].Add(sLogin);
newUser.CommitChanges();
objUser = (ActiveDs.IADsUser) newUser.NativeObject;
objUser.AccountDisabled = false;
objUser.SetInfo();
objUser.ChangePassword("",sPassword);
objUser.FullName = sLogin;
newUser.CommitChanges();
objUser.SetInfo();
objMailbox = (CDOEXM.IMailboxStore) objUser;//Now it works!Thanks Dave
and Steve
//Create a mailbox for the recipient
//You cannot create a mailbox using ADSI, so use CDOEXM
//These values will differ for other organizations
// Here I build the String
string HomeMDBURL = "LDAP://" + ServerName + "/CN=" + strMDB +
",CN=First Storage Group,CN=InformationStore,CN=" + ServerName +
",CN=Servers,CN=First Administrative Group," +
"CN=Administrative Groups,CN=DGAProtoOrga," +
"CN=Microsoft Exchange,CN=Services," +
"CN=Configuration," + DomainName;
objMailbox.CreateMailbox(HomeMDBURL);//There I got my error.
objUser.SetInfo();
return true;
}
<CODE>
>Now I get an "System.ArgumentException: The parameter is incorrect."
>at the line
>objMailbox.CreateMailbox(HomeMDBURL)
Strange. Does the same string work from VB6?
Wild guess; are the regional settings the same on both machines?
--
Steve Walker
Men are from earth. Women are from earth. Deal with it.
steve at otolith dot demon dot co dot uk
http://www.otolith.demon.co.uk
>Does the same string work from VB6?
Yes! the same string DOES work fine from VB6 on THE SAME machine.
The only differences is that
-my VB6 test is a stand alone application and my code is run through a
ASP.NET c# web application...
-In the c# code i work with a DirectoryEntry to create the user.(not
the IADsContainer)
Here's the VB code:
<CODE>
Function ADSICreateMailBoxRecipient(ServerName As String, _
DomainName As String, _
emailname As String, _
FirstName As String, _
LastName As String) As Integer
'ServerName is something like "MyServer"
'DomainName is something like "DC=my,DC=domain,DC=com"
'emailname is something like "jamessmith"
Dim strMDB As String
Dim objUser As IADsUser
Dim objContainer As IADsContainer
Dim objMailbox As CDOEXM.IMailboxStore
Dim recipname As String, recip As String
strMDB = "MailBox Store (MYSERVER)"
recip = "CN=" & emailname
MsgBox "Début procédure ajout"
' get the container
Set objContainer = GetObject("LDAP://" + ServerName + "/" + _
"CN=users," + DomainName)
' create a recipient
Set objUser = objContainer.Create("User", recip)
objUser.Put "samAccountName", emailname
objUser.Put "sn", LastName
objUser.Put "givenName", FirstName
objUser.Put "userPrincipalName", emailname
objUser.SetInfo
' objUser.SetPassword ("password")
objUser.AccountDisabled = False
'Works fine now:
Set objMailbox = objUser
'Create a mailbox for the recipient
'You cannot create a mailbox using ADSI, so use CDOEXM
objMailbox.CreateMailbox "LDAP://" + ServerName + _
"/CN=" + strMDB + _
",CN=First Storage
Group,CN=InformationStore,CN=" + _
ServerName + _
",CN=Servers,CN=First Administrative Group,"
+ _
"CN=Administrative Groups,CN=DGAProtoOrga," +
_
"CN=Microsoft Exchange,CN=Services," + _
"CN=Configuration," + DomainName
objUser.SetInfo
MsgBox "Fin procédure ajout"
End Function
</CODE>
> Wild guess; are the regional settings the same on both machines?
Which machines? my machine and the Exchange Server? Yes. They're both
W2K English version configured with French regional settings,
According to "Start...Settings...Control Panel...Regional Options"
Deeply peculiar. I guess there will be a few odd things coming out of
the woodwork in the next few months!
>>Does the same string work from VB6?
>Yes! the same string DOES work fine from VB6 on THE SAME machine.
>> Wild guess; are the regional settings the same on both machines?
>Which machines? my machine and the Exchange Server? Yes. They're both
>W2K English version configured with French regional settings,
>According to "Start...Settings...Control Panel...Regional Options"
Hmm. I only ask because some of the system classes will throw that error
if your code is compiled with one regional setting and run on one with
another. I wondered whether .NET was doing something clever with
character sets that CDOEXM doesn't understand, on the Exchange box. I'd
have thought that French would make no difference, since most of the
examples were Chinese or Russian... 8o)
I think my next step would be to write a COM component in VB6 that
accepted a string, and call it from .NET, passing your HomeMDBURL string
to it and seeing what it made of it. If what it gets matches the string
that works in VB6, then I think you're up against a real problem finding
a pure .NET way round this, and it may be a good idea to write a VB6
wrapper for the functionality you need. Otherwise, it may give a clue to
the problem.
Sudden thought; why not use System.DirectoryServices in the .NET
framework? There isn't a specific provider for Exchange, but there is
one for LDAP. Is Exchange fully LDAP compliant?
> I think my next step would be to write a COM component in VB6
I won't be so pessimistic...
In this thread (Message Number 6)
http://groups.google.com/groups?q=CDOEXM+boring&hl=en&btnG=Google+Search
David Stucki gave me a sample code that "DOES" work on his machine.
So...
>
> Sudden thought; why not use System.DirectoryServices in the .NET
> framework? There isn't a specific provider for Exchange, but there is
> one for LDAP. Is Exchange fully LDAP compliant?
I'm afraid CDOEXM is necessary to create the mailbox. I mean: using an
IMailboxStore type object is the ONLY way to do it...
I am puzzled.. :-[
Num