Skip to content

Instantly share code, notes, and snippets.

@LQ80
Last active May 5, 2020 21:24
Show Gist options
  • Save LQ80/6cb70ecafb8994132c1e3c2fccde242b to your computer and use it in GitHub Desktop.
Save LQ80/6cb70ecafb8994132c1e3c2fccde242b to your computer and use it in GitHub Desktop.
hMailServer Create User Accounts
'hMailServer Create User Accounts:
'=================================
'
'This also requires a CSV file called Users.csv in the same directory as the script. The CSV is in the following format:
'username,password,domain
Option Explicit
Dim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewUser,i
Const ForReading = 1
Set obBaseApp = CreateObject("hMailServer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("Users.csv", ForReading)
'Authentication
Const sAdminPassword = "<ADMINISTRATORPASSWORD>"
Call obBaseApp.Authenticate ("Administrator", sAdminPassword)
Do While objTextFile.AtEndOfStream <> True
strNewUser = split(objTextFile.Readline, ",")
AddUser strNewUser(0), strNewUser(1), strNewUser(2)
i = i + 1
Loop
Sub AddUser(strUsername, strPassword, strDomain)
Dim obDomain
Dim obAccounts
Dim obNewAccount
Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
Set obAccounts = obDomain.Accounts
Set obNewAccount = obAccounts.Add()
obNewAccount.Address = strUsername & "@" & strDomain 'username
obNewAccount.Password = strPassword 'password
obNewAccount.Active = 1 'activates user
obNewAccount.Maxsize = 0 'sets mailbox size, 0=unlimited
obNewAccount.Save() 'saves account
Set obNewAccount = Nothing
Set obDomain = Nothing
Set obAccounts = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment