' ==================================================== ' ' NAME ' ---- ' hmail-create-account.vbs - Automate Account Creation for hMailServer ' ' SYNOPSIS ' -------- ' Run from command line with "start hmail-create-account.vbs USERNAME PASSWORD DOMAIN" ' ' DESCRIPTION ' ----------- ' The script is indempotent. This means that if the account/domain combination ' already exists, nothing will happen. ' ' LICENSE ' ------- ' This script is provided under the Apache License, Version 2.0 ' For details, please look at http://www.apache.org/licenses/LICENSE-2.0 ' ' AUTHOR ' ------ ' Christoph Jahn - http://www.christoph-jahn.com/?p=1280 ' ' ==================================================== 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 = "" '=============================================================== ' No changes below this line '=============================================================== ' 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.Add() domain.Name=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=accountList.Add() account.Address=email account.Password=userPassword account.Active=true account.Save() end if