Guys,
I am working on a new web site for our company and have started to move my
code from VB.Net to C#. I have ran into a snag that I can't seem to figure
out. I am trying to create an Exchange mailbox for a user ID that I just
created using System.DirectoryServices. I have created the user, set the
password, and enabled the account.
When I try and create the mailbox I get a "The parameter is incorrect" error
message on mailbox.CreateMailbox(strServe); line. I have ran just about
100% of this code in VB.Net and it works great. I tracted back the
strServer in the configuration view of ADSI Edit. It appears to be correct
and if I take the exact text it creates and put it in a VB app it works.
It looks like it's the way I am implementing the following two lines.
mailbox = (IMailboxStore)oUser.NativeObject;
mailbox.CreateMailbox(strServer);
The stack trace on the error page is showng this
[ArgumentException: The parameter is incorrect.]
CDOEXM.IMailboxStore.CreateMailbox(String HomeMDBURL) +0
Crossmark.Enterprise.CAPUserCreate.Common.Exchange .CreateMailBox(String
strUserPath, String MailBoxEnding, Char firstletter) in c:\documents and
settings\tim.sapp\my documents\visual studio
projects\crossmark.enterprise.capusercreate\crossm ark.enterprise.capusercreate.common\exchange.cs:89
Crossmark.Enterprise.CAPUserCreate.UI._default.Cre ateUser_Button_Click(Object
sender, EventArgs e) in
c:\inetpub\wwwroot\crossmark.enterprise.capusercre ate.ui\default.aspx.cs:122
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
Looks like it does not list the strServer when it tries to put the info into
the user account.
I am using the same security premissons in the VB and C# app so I know that
is not a problem.
When I put the create mail in a try the exception message is "The parameter
is incorrect" and the InnerException is blank.
Here is what I am running on...
DevBox
WinXP Pro
Visual Studio 2003
..Net Framework 1.1 (1.1.4322 SP1)
CDO Exchange Managment installed.
-
Exchange 2003
(Running on Windows 2003)
-
Active Directory
Windows 2003 (No Mixed Mode)
//************************************************** *******
//************************************************** *******
using System;
using System.DirectoryServices;
using CDOEXM;
namespace Crossmark.Enterprise.CAPUserCreate.Common
{
/// <summary>
/// Summary description for Exchange.
/// </summary>
public class Exchange
{
protected string ServerName;
protected string StorageGroup;
protected IMailboxStore mailbox;
public bool CreateMailBox( string strUserPath, string MailBoxEnding, char
firstletter)
{
DirectoryEntry oUser = new DirectoryEntry(strUserPath);
oUser.Username = Common.Constants.ActiveDirectorySettings.ADUserNam e;
oUser.Password = Common.Constants.ActiveDirectorySettings.ADPasswor d;
int temp = Convert.ToInt32(firstletter);
switch(temp)
{
case 65:
case 66:
ServerName = "CN=DALEXCBE01";
StorageGroup = "CN=AB" + MailBoxEnding + "CN=AB";
break;
case 67:
case 68:
ServerName = "CN=DALEXCBE01";
StorageGroup = "CN=CD" + MailBoxEnding + "CN=CD";
break;
case 69:
case 70:
case 71:
ServerName = "CN=DALEXCBE01";
StorageGroup = "CN=EG" + MailBoxEnding + "CN=EG";
break;
case 72:
case 73:
case 74:
ServerName = "CN=DALEXCBE02";
StorageGroup = "CN=HJ" + MailBoxEnding + "CN=HJ";
break;
case 75:
case 76:
ServerName = "CN=DALEXCBE02";
StorageGroup = "CN=KL" + MailBoxEnding + "CN=KL";
break;
case 77:
case 78:
case 79:
ServerName = "CN=DALEXCBE02";
StorageGroup = "CN=MO" + MailBoxEnding + "CN=MO";
break;
case 80:
case 81:
case 82:
ServerName = "CN=DALEXCBE03";
StorageGroup = "CN=PR" + MailBoxEnding + "CN=PR";
break;
case 83:
ServerName = "CN=DALEXCBE03";
StorageGroup = "CN=S" + MailBoxEnding + "CN=S";
break;
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
ServerName = "CN=DALEXCBE03";
StorageGroup = "CN=TZ" + MailBoxEnding + "CN=TZ";
break;
}
string strServer = @"LDAP://DALADINT01/" + StorageGroup +
",CN=InformationStore," + ServerName +
",CN=Servers,CN=Dallas,CN=Administrative Groups,CN=CROSSMARK,CN=Microsoft
Exchange,CN=Services,CN=Configuration,DC=Internal, DC=PVT";
try
{
mailbox = (IMailboxStore)oUser.NativeObject;
mailbox.CreateMailbox(strServer);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
if (MailBoxEnding == "PT1")
{
oUser.Properties["submissionContLength"].Value = "2000";
oUser.Properties["delivContLength"].Value = "2000";
}
oUser.CommitChanges();
return true;
}
} // End Exchange Class
} // End Namespace
Thanks for any help that yall con provide.
Tim