using System;
using CDOEXM;
using System.DirectoryServices;
using ActiveDs;
using System.Windows.Forms;
namespace MBTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// try
// {
//TODO: Change these items to values for your domain or organization.
string defaultNC = "DC=VIVTECH,DC=com";
string alias = "test1";
string fullName = "test1";
string password = "123456";
//string domainName = "VIVTECH.com";
/*string homeMDB = "CN=SOFTTEAM,CN=第一个存储组,"
+ "CN=InformationStore,CN=MAIL,CN=Servers,"
+ "CN=First Administrative Group,CN=Administrative Groups,"
+ "CN=First Organization,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=VIVTECH,DC=Com";*/
string homeMDB = "CN=SOFTTEAM,CN=SOFTTEAM,"
+ "CN=InformationStore,CN=MAIL,CN=Servers,"
+ "CN=First Administrative Group,CN=Administrative Groups,"
+ "CN=First Organization,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=VIVTECH,DC=Com"; DirectoryEntry container, user;
CDOEXM.IMailboxStore mailbox; //This creates the new user in the "users" container.
//Set the sAMAccountName and the password
container = new DirectoryEntry("LDAP://cn=users," + defaultNC);
user = container.Children.Add("cn=" + fullName, "user");
user.Properties["sAMAccountName"].Add(alias);
user.CommitChanges();
//user.Invoke("SetPassword", new object[]{password});
// user.Properties["userPassword"].Add(password);
// user.Invoke("SetPassword", new object[]{password});
//This enables the new user.
//user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
//user.CommitChanges(); //Obtain the IMailboxStore interface, create the mailbox, and commit the changes.
//IADsUser adsUser = (IADsUser) Microsoft.VisualBasic.Interaction.GetObject(user.Path, null); ActiveDs.IADsUser adsUser = (IADsUser) user.NativeObject;
mailbox = (IMailboxStore) adsUser; //mailbox = (IMailboxStore)user.NativeObject;
mailbox.CreateMailbox(homeMDB);
//user.CommitChanges();
// }
// catch (Exception s)
// {
// MessageBox.Show(s.Message);
// } return;
}
}
}运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。 at CDOEXM.IMailboxStore.CreateMailbox(String HomeMDBURL) at MBTest.Class1.Main(String[] args) in c:\documents and ettings\administrat
or\my documents\visual studio projects\mbtest\class1.cs:line 59”拜托了
我目前最多只被允许给100分,问题解决的话可另开贴给分
using CDOEXM;
using System.DirectoryServices;
using ActiveDs;
using System.Windows.Forms;
namespace MBTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// try
// {
//TODO: Change these items to values for your domain or organization.
string defaultNC = "DC=VIVTECH,DC=com";
string alias = "test1";
string fullName = "test1";
string password = "123456";
//string domainName = "VIVTECH.com";
/*string homeMDB = "CN=SOFTTEAM,CN=第一个存储组,"
+ "CN=InformationStore,CN=MAIL,CN=Servers,"
+ "CN=First Administrative Group,CN=Administrative Groups,"
+ "CN=First Organization,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=VIVTECH,DC=Com";*/
string homeMDB = "CN=SOFTTEAM,CN=SOFTTEAM,"
+ "CN=InformationStore,CN=MAIL,CN=Servers,"
+ "CN=First Administrative Group,CN=Administrative Groups,"
+ "CN=First Organization,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=VIVTECH,DC=Com"; DirectoryEntry container, user;
CDOEXM.IMailboxStore mailbox; //This creates the new user in the "users" container.
//Set the sAMAccountName and the password
container = new DirectoryEntry("LDAP://cn=users," + defaultNC);
user = container.Children.Add("cn=" + fullName, "user");
user.Properties["sAMAccountName"].Add(alias);
user.CommitChanges();
//user.Invoke("SetPassword", new object[]{password});
// user.Properties["userPassword"].Add(password);
// user.Invoke("SetPassword", new object[]{password});
//This enables the new user.
//user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
//user.CommitChanges(); //Obtain the IMailboxStore interface, create the mailbox, and commit the changes.
//IADsUser adsUser = (IADsUser) Microsoft.VisualBasic.Interaction.GetObject(user.Path, null); ActiveDs.IADsUser adsUser = (IADsUser) user.NativeObject;
mailbox = (IMailboxStore) adsUser; //mailbox = (IMailboxStore)user.NativeObject;
mailbox.CreateMailbox(homeMDB);
//user.CommitChanges();
// }
// catch (Exception s)
// {
// MessageBox.Show(s.Message);
// } return;
}
}
}运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。 at CDOEXM.IMailboxStore.CreateMailbox(String HomeMDBURL) at MBTest.Class1.Main(String[] args) in c:\documents and ettings\administrat
or\my documents\visual studio projects\mbtest\class1.cs:line 59”拜托了
我目前最多只被允许给100分,问题解决的话可另开贴给分
http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;313114&product=vcSnet如何使用 C# .NET 创建一个启用了邮箱的收件人
我的程序就是在那个例子的基础上改的,我不大明白string homeMDB =到底该写些什么
user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
user.CommitChanges();
这两句的话,运行时会报错‘该服务器不愿意处理该请求’
这句出错,运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。谁能告诉我homeMDB这个参数里到底该写些什么????
你可以去EXCHANGE里看看是怎么设置的.//这个是StorageGroup
string homeMDB = "CN=Mailbox Store (Your Server),CN=Your Storage Group,"//这个是MailboxStoreDB了
+ "CN=InformationStore,CN=Your Server,CN=Servers,"//这个大概就是PublicStoreDB了
+ "CN=Your Administrative Group,CN=Administrative Groups,"//再下面的我也不清楚的啦.
+ "CN=Your Org,CN=Microsoft Exchange,CN=Services,"
+ "CN=Configuration,DC=Yourdomain,DC=Com";
user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
user.CommitChanges();
这两句的话,运行时会报错‘该服务器不愿意处理该请求’在这里你是怎么解决的?
The123(一个正确的问题比一个正确的答案重要得多...)“InformationStore这个邮箱存储(MailboxStoreDB)有没有创建?
你可以去EXCHANGE里看看是怎么设置的.”到哪里去看?
{
DirectoryEntry container,user;
container = new DirectoryEntry("LDAP://cn=Users,DC=hipc,DC=com");
foreach(DirectoryEntry ee in container.Children)
MessageBox.Show(ee.Path);
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}运行,catch到异常,"从服务器返回了一个参照"这里的Users是Active Directory中的一个容器吧?
那里错了?
这句出错,运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。
俺也碰到这问题,楼主要是解决了,别忘了共享呀!
其中:
TEST = 你的机子名(netbios名)
MailOrg = 你在exchange里创建的组织,就是顶层根名
DC=mail,DC=com = 你的域名(eg: microsoft.com)
注意:
如果此代码在不是基于 Exchange 2000 Server 的计算机上运行,您必须在该计算机上安装 Exchange 2000 系统管理工具。如果不这样做,则 CDOEXM 将不可用,而且向 IMailboxStore 的强制转换将导致返回 InvalidCastException 响应:
An unhandled exception of type 'System.InvalidCastException' occurred in MBTest.exe
Additional information:Specified cast is not valid.