2019独角兽企业重金招聘Python工程师标准>>>
将内容复制到txt文件中后缀改为vbs
将用户名密码替换为自己的
脚本内容如下:
Option Explicit
On Error resume nextDim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewAlias,iDim scrreport
Dim failed
Dim added
failed = 0
added = 0Const ForReading = 1Set obBaseApp = CreateObject("hMailServer.Application")Call obBaseApp.Authenticate("Administrator","password") '*** N.B. 1. set your administrator password in this line
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("users.txt", ForReading) ' *** N.B. 2. Set your CSV path/filename in this line
Do While objTextFile.AtEndOfStream <> True
strNewAlias = split(objTextFile.Readline, ",")Select Case strNewAlias(0)
Case "User"
AddUser strNewAlias(1), strNewAlias(2), strNewAlias(3)
Case "Alias"
AddAlias strNewAlias(1), strNewAlias(2), strNewAlias(3)
End Select
If err.Number <> 0 Then 'error handling:
scrreport = scrreport & "Failed add (probably duplicate) : " & strNewAlias(0) & "," & strNewAlias(1) & "," & strNewAlias(2) & "," & strNewAlias(3) & VBNewLine
failed = failed + 1
err.Clear
Else
added = added + 1
End Ifi = i + 1
Loopscrreport = scrreport & " " & VBNewLine
scrreport = scrreport & "Added = " & added & VBNewLine
scrreport = scrreport & "Failed or Duplicates = " & failed & VBNewLine
wscript.echo scrreportSub AddAlias(strAlias,strEmailAddress,strDomain)
Dim obDomain
Dim obAliases
Dim obNewAliasSet obDomain = obBaseApp.Domains.ItemByName(strDomain)
Set obAliases = obDomain.Aliases
Set obNewAlias = obAliases.Add() obNewAlias.Name = strAlias & "@" & strDomain 'username
obNewAlias.Value = strEmailAddress 'password
obNewAlias.Active = 1 'activates user
obNewAlias.Save() 'saves accountSet obNewAlias = Nothing
Set obAliases = Nothing
Set obDomain = Nothing End SubSub AddUser(strUsername, strPassword, strDomain)
Dim obDomain
Dim obAccounts
Dim obNewAccountSet 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 = 500 'sets mailbox size, 0=unlimited
obNewAccount.Save() 'saves accountSet obNewAccount = Nothing
Set obDomain = Nothing
Set obAccounts = NothingEnd Sub
users.txt示例
User,tom,password,xxxx.com
Alias,jim,tom@xxxx.com,xxxx.com
会在xxxx.com域添加一个用户名为tom 密码为password的用户,并创建将jim@xxxx.com转发至tom@xxxx.com
参考 https://www.hmailserver.com/forum/viewtopic.php?t=2206