用C#在域中增加用户和邮箱
来源:互联网 发布:acrobat 2018 for mac 编辑:程序博客网 时间:2024/06/05 01:15
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
{
string p_strDomainLoginName="admin";
string p_strDomainLoginPassword="";
string p_strDomainName="myweb.com";
string p_strDCName="DC=myweb,DC=com";
string p_strServerName="myweb";
int ReturnValue;
CDO.PersonClass pcUser;
CDOEXM.IMailboxStore MailBox;
string strLDAP="LDAP://" + p_strDomainName + "/CN=" + loginname + ",CN=users," + p_strDCName;
string strHomeMDBURL="LDAP://" + p_strDomainName + "/CN=Mailbox Store (" + p_strServerName + ")," +
"CN=First Storage Group,CN=InformationStore," +
"CN=" + p_strServerName + ",CN=Servers,CN=First Administrative Group," +
"CN=Administrative Groups,CN=First Organization," +
"CN=Microsoft Exchange,CN=Services,CN=Configuration," + p_strDCName;
if (loginname.Length>0)
{
try
{
//增加用户
pcUser=new PersonClass();
pcUser.FirstName=loginname;
pcUser.LastName="";
pcUser.Fields["userAccountControl"].Value=66048; //设置该用户密码永不过期
pcUser.Fields["userPrincipalName"].Value=loginname; //设置用户的登录帐号
pcUser.Fields.Update();
pcUser.DataSource.SaveTo(strLDAP,null,ADODB.ConnectModeEnum.adModeReadWrite ,
ADODB.RecordCreateOptionsEnum.adCreateOverwrite,ADODB.
RecordOpenOptionsEnum.adOpenSource,p_strDomainLoginName,p_strDomainLoginPassword);
//添加邮箱
MailBox=(IMailboxStore)pcUser.GetInterface("IMailboxStore");
MailBox.CreateMailbox(strHomeMDBURL);
pcUser.Email="SMTP:" + loginname + "@" + p_strDomainName;
pcUser.Fields["mailnickname"].Value="mailnickname" + loginname;
pcUser.Fields.Update();
pcUser.DataSource.Save();
ReturnValue=1;
}
catch
{
ReturnValue=-1;
}
}
else
{
ReturnValue=-1;
}
return ReturnValue;
}
注意引用CDO和CDOEXM。
欢迎互相交流。
域中增加用户和邮箱';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
public int CreatUser(string loginname){
string p_strDomainLoginName="admin";
string p_strDomainLoginPassword="";
string p_strDomainName="myweb.com";
string p_strDCName="DC=myweb,DC=com";
string p_strServerName="myweb";
int ReturnValue;
CDO.PersonClass pcUser;
CDOEXM.IMailboxStore MailBox;
string strLDAP="LDAP://" + p_strDomainName + "/CN=" + loginname + ",CN=users," + p_strDCName;
string strHomeMDBURL="LDAP://" + p_strDomainName + "/CN=Mailbox Store (" + p_strServerName + ")," +
"CN=First Storage Group,CN=InformationStore," +
"CN=" + p_strServerName + ",CN=Servers,CN=First Administrative Group," +
"CN=Administrative Groups,CN=First Organization," +
"CN=Microsoft Exchange,CN=Services,CN=Configuration," + p_strDCName;
if (loginname.Length>0)
{
try
{
//增加用户
pcUser=new PersonClass();
pcUser.FirstName=loginname;
pcUser.LastName="";
pcUser.Fields["userAccountControl"].Value=66048; //设置该用户密码永不过期
pcUser.Fields["userPrincipalName"].Value=loginname; //设置用户的登录帐号
pcUser.Fields.Update();
pcUser.DataSource.SaveTo(strLDAP,null,ADODB.ConnectModeEnum.adModeReadWrite ,
ADODB.RecordCreateOptionsEnum.adCreateOverwrite,ADODB.
RecordOpenOptionsEnum.adOpenSource,p_strDomainLoginName,p_strDomainLoginPassword);
//添加邮箱
MailBox=(IMailboxStore)pcUser.GetInterface("IMailboxStore");
MailBox.CreateMailbox(strHomeMDBURL);
pcUser.Email="SMTP:" + loginname + "@" + p_strDomainName;
pcUser.Fields["mailnickname"].Value="mailnickname" + loginname;
pcUser.Fields.Update();
pcUser.DataSource.Save();
ReturnValue=1;
}
catch
{
ReturnValue=-1;
}
}
else
{
ReturnValue=-1;
}
return ReturnValue;
}
注意引用CDO和CDOEXM。
欢迎互相交流。
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 用C#在域中增加用户和邮箱
- sendmail增加邮箱用户
- .Net 判断邮箱在域中是否存在
- 在域中批量添加用户
- exchange 2013 如何批量启用域中已存在用户但未开通邮箱的账号的邮箱
- 转换特殊符号,防止用户在文本域中输入html标签
- 在另一个应用程序域中执行代码(C# 编程指南)
- 批量创建用户和邮箱
- 桑梓团队使用Google Apps域中的邮箱的smtp和pop的配置
- 用户在注册成功后,发送用户名和密码到其注册邮箱的方法
- 查看域中所有的用户
- 向域中批量创建用户
- google邮箱容量真的不断在增加吗?
- vsftpd增加用户和限制用户配置
- 使用C#代码实现增加用户帐号
- 使用C#代码实现增加用户帐号
- 如何检查Windows用户在域中的合法性(存在、合法)
- 在Active Directory域中限制用户并发登录:LimitLogin VS UserLock(一)
- ORACLE坏块(ORA-01578)处理方法
- 关于c#中的消息处理函数和vc中的消息处理函数区别
- ORACLE DBA常用SQL脚本工具->管理篇(1)
- C#中键盘钩子的使用(转)
- 让你的应用程序不再对数据库的改动“感冒”(二)
- 用C#在域中增加用户和邮箱
- 在你的JDeveloper里扩展J2ME
- 微软SQL Server 2000 Reporting Services介绍(四)
- 在DB2中如何實現Oracle的相關功能(三)
- 处理异常的最佳做法
- 在单机上创建物理的Oracle9i standby数据库
- XML、Web服务和.NET框架
- 如何在SQL Server2000中处理半个汉字的问题
- 字符串加解密的类(VB.NET Source Code)