我只是在http://www.hmailserver.com/documentation/latest/?page=com_example_account_create下面提供了hMailServer的DCOM API提供的以下代码。以下脚本运行正常。它没有任何参考。在安装hMailServer之后,运行以下代码可以创建一个帐户。现在,我在C#中需要相同的东西。他们没有为我提供任何C#我用Google搜索的库,但我没有相关的结果是下面的代码,但根据hMailServer API,他们说你可以将下面的脚本转换成你想要的任何语言。但是怎么样?我甚至不知道如何开始写第一行。有人请帮助我。
Dim obApp
Set obApp = CreateObject("hMailServer.Application")
' Authenticate. Without doing this, we won't have permission
' to change any server settings or add any objects to the
' installation.
Call obApp.Authenticate("Administrator", "your-main-hmailserver-password")
' Locate the domain we want to add the account to
Dim obDomain
Set obDomain = obApp.Domains.ItemByName("example.com")
Dim obAccount
Set obAccount = obDomain.Accounts.Add
' Set the account properties
obAccount.Address = "account@example.com"
obAccount.Password = "secret"
obAccount.Active = True
obAccount.MaxSize = 100 ' Allow max 100 megabytes
obAccount.Save
答案 0 :(得分:8)
将COM对象(hMailServer)添加到C#项目作为参考,并将其余代码转换为C#。
看起来像这样:
var app = new hMailServer.Application();
// Authenticate. Without doing this, we won't have permission
// to change any server settings or add any objects to the
// installation.
app.Authenticate("Administrator", "your-main-hmailserver-password");
// Locate the domain we want to add the account to
var domain = app.Domains["example.com"];
var account = domain.Accounts.Add();
// Set the account properties
account.Address = "account@example.com";
account.Password = "secret";
account.Active = true;
account.MaxSize = 100; // Allow max 100 megabytes
account.Save();
答案 1 :(得分:2)
我希望这仍然有用,可以帮助别人。在这里,我只使用get item by name属性来提取hMailServer中配置的域名。
protected void Page_Load(object sender, EventArgs e)
{
var app = new hMailServer.Application();
// Authenticate. Without doing this, we won't have permission
// to change any server settings or add any objects to the
// installation.
app.Authenticate("Administrator", "your.admin.password.here");
// Locate the domain we want to add the account to
var domain = app.Domains.get_ItemByName("your.configured.domain.name.here");
var account = domain.Accounts.Add();
// Set the account properties
account.Address = "account.name.here";
account.Password = "pass.word.here";
account.Active = true;
account.MaxSize = 100; // Allow max 100 megabytes
account.Save();
}