Below is my script. Any input regards my finger fault greatly appreciate. I can't see the tress for the forest.
Code: Select all
Dim hmail, domain, account, email, noOfDomains, userName, userPassword, domainName, hMailAdminAccount, hMailAdminPassword
' These are the hMail admin account defaults after a silent install
hMailAdminAccount = "Administrator"
hMailAdminPassword = "myenteredpasswordgoeshere"
' Check for account details from command line
If Wscript.Arguments.Count <> 3 Then
WScript.Quit 1
End If
userName = Wscript.Arguments(0)
userPassword = Wscript.Arguments(1)
domainName = Wscript.Arguments(2)
'msgbox userName & " / " & userPassword & " @ " & domainName,0,"Input params"
email = userName & "@" & domainName
' Get connection to hMailServer
Set hmail = CreateObject("hMailServer.Application")
hmail.Authenticate hMailAdminAccount,hMailAdminPassword
' Check whether domain already exists
noOfDomains = hmail.Domains.Count
domainExists = false
if noOfDomains > 0 then
for i = 0 to noOfDomains-1
set domain = hmail.Domains.Item(i)
if domain.Name = domainName then
domainExists = True
exit for
end if
next
end if
' Create domain if it does not yet exist
if domainExists = false
then
Set domain = hmail.Domains.ItemByName(domainName)
domain.Active = True
domain.Save
end if
' Check whether account already exists
Set accountList=domain.Accounts
noOfAccount = accountList.Count
accountExists = false
if noOfAccount > 0 then
for i = 0 to noOfAccounts
Set account = accountList.Item(i)
if account.Address = email then
accountExists = True
exit for
end if
next
end if
' Create account if it does not yet exist
if accountExists = false
then
Set account = hmail.Accounts.Add
account.Address=email
account.Password=userPassword
account.Active = True
account.MaxSize = 100 ' Allow max 100 megabytes
account.Save
end if