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分,问题解决的话可另开贴给分

解决方案 »

  1.   

    使用directoy的命名空间,给服务器加上一个用户,开通邮箱就是了。
      

  2.   

    参考
    http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;313114&product=vcSnet如何使用 C# .NET 创建一个启用了邮箱的收件人
      

  3.   

    http://support.microsoft.com/kb/313114/zh-cn
      

  4.   

    TO net_lover(孟子E章)
    我的程序就是在那个例子的基础上改的,我不大明白string homeMDB =到底该写些什么
      

  5.   

    而且如果启用
    user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
    user.CommitChanges();
    这两句的话,运行时会报错‘该服务器不愿意处理该请求’
      

  6.   

    现在‘该服务器不愿意处理该请求’的错误已经没了运行程序后,用户是建立成功,但邮箱还是未创建,仍然是mailbox.CreateMailbox(homeMDB);
    这句出错,运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。谁能告诉我homeMDB这个参数里到底该写些什么????
      

  7.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wss/wss/_exch2k_cdo_for_exchange_management_objects.aspInformationStore这个邮箱存储(MailboxStoreDB)有没有创建?
    你可以去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";
      

  8.   

    而且如果启用
    user.Properties["userAccountControl"].Value = 0x200; //ADS_UF_NORMAL_ACCOUNT
    user.CommitChanges();
    这两句的话,运行时会报错‘该服务器不愿意处理该请求’在这里你是怎么解决的?
      

  9.   

    http://www.microsoft.com/downloads/details.aspx?amp;displaylang=en&familyid=5b7d2110-a322-4947-9eaf-3d6a9a99cb42&displaylang=en
      

  10.   

    rubbishbug(垃圾虫)重新建个项目,它就对了,莫名其妙啊
     The123(一个正确的问题比一个正确的答案重要得多...)“InformationStore这个邮箱存储(MailboxStoreDB)有没有创建?
    你可以去EXCHANGE里看看是怎么设置的.”到哪里去看?
      

  11.   

    try
    {
    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中的一个容器吧?
    那里错了?
      

  12.   

    运行程序后,用户是建立成功,但邮箱还是未创建,仍然是mailbox.CreateMailbox(homeMDB);
    这句出错,运行后总有如下提示:“未处理的异常: System.Runtime.InteropServices.COMException (0x80072030): 在服务器上没有这样一个对象。
    俺也碰到这问题,楼主要是解决了,别忘了共享呀!
      

  13.   

    创建邮箱是可以成功的,但是怎么用CDOEXM管理邮箱(如:发送、删除、移动邮件)?CDOEXM可是Exchange带的LIB呀,应该会提供这些功能呀?用EasyMail会碰到的问题:http://community.csdn.net/Expert/topic/3533/3533344.xml?temp=4.987735E-02
      

  14.   

    lijing2001(123)你是如何解决的,我始终不行
      

  15.   

    homeMDB="CN=邮箱存储(TEST),CN=第一个存储组,CN=InformationStore,CN=TEST,CN=Servers,CN=第一个管理组,CN=Administrative Groups,CN=MailOrg,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=mail,DC=jci"
    其中:
    TEST = 你的机子名(netbios名)
    MailOrg = 你在exchange里创建的组织,就是顶层根名
    DC=mail,DC=com = 你的域名(eg: microsoft.com)
      

  16.   

    http://support.microsoft.com/kb/313114/zh-cn
    注意:
    如果此代码在不是基于 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.