Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 post(s)
|
please named your alias content as alias.csv Code:list1@localhost,list 1 mailing list,enabled,ismailinglist,subscribe,unsubscribe
list2@localhost,list 2 mailing list,enabled,ismailinglist,subscribe,unsubscribe
and save the following content as ImportFromAliasCSV.vbs Code:
Dim args, info
Set args = WScript.Arguments
If args.Count < 3 Then
info = "Usage: ImportFromAliasCSV.vbs [password of system] [domain] [csv file]" & Chr(13) & Chr(10)
info = info & " eg: ImportFromAliasCSV.vbs mypass emailarchitect.net alias.csv"
WScript.Echo info
WScript.Quit
End If
Dim hRes
Dim oSvr, oDomainCollection, oDomain
Set oSvr = CreateObject("EmailArchitectObjects.ServerRoot")
hRes = oSvr.Connect( "localhost", "system", Trim(args(0)), 0 )
If hRes <> 0 Then
WScript.Echo "Connecting server failed!"
WScript.Quit()
End If
Set oDomainCollection = oSvr.DomainCollection
Set oDomain = oDomainCollection.Items( Trim(args(1)))
If oDomain Is Nothing Then
WScript.Echo "domain doesn't existed, please create specified domain at first!"
WScript.Quit()
End If
Const ForReading = 1
Dim fso, f
Dim csvname, fname
csvname = Trim(args(2))
If InStr( 1, csvname, ":" ) <= 0 Then
fname = WScript.ScriptFullName 'csvname is not a full path, convert it.
Dim pos
pos = InStrRev( fname, "\" )
fname = Mid( fname, 1, pos )
csvname = fname & csvname
End If
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile( csvname, ForReading, False )
Dim s, nIndex
nIndex = 0
Do While( f.AtEndOfStream <> True )
s = f.ReadLine()
Call fnTrim( s, " ," & Chr(10) & Chr(13) & Chr(9))
If s <> "" Then
CreateAlias oDomain, s, nIndex
End If
nIndex = nIndex + 1
Loop
f.Close()
Sub CreateAlias( ByRef oDomain, ByRef account, ByRef nIndex )
Dim arTemp
arTemp = Split( account, "," )
Dim i, nCount
nCount = UBound(arTemp)
If (nCount - LBound(arTemp)) < 5 Then
Exit Sub
End If
WScript.Echo Chr(13) & Chr(10)
WScript.Echo "***********************************************************"
WScript.Echo nIndex & ": Processing " & account & " ..."
WScript.Echo "***********************************************************"
Set oUserCollection = oDomain.UserCollection
Dim user, description, enabled, ismailinglist, subscribe, unsubscribe, emaillist
user = LCase(Trim(arTemp(LBound(arTemp))))
description = Trim(arTemp(LBound(arTemp)+1))
enabled = Trim(arTemp(LBound(arTemp)+2))
ismailinglist = Trim(arTemp(LBound(arTemp)+3))
subscribe = Trim(arTemp(LBound(arTemp)+4))
unsubscribe = Trim(arTemp(LBound(arTemp)+5))
Dim pos
pos = InStr(1, user, "@")
If pos > 0 Then
user = Mid(user, 1, pos - 1)
End If
Const AUTH_USER_SEND = 8
Const ALIAS_LIST = 16
Const SENDER_IN_LIST = 32
Dim active, flags
active = 0
flags = 0
If LCase(enabled) = "yes" Or LCase(enabled) = "true" Or LCase(enabled) = "enabled" Then
active = 1
End If
If LCase(ismailinglist) = "yes" Or LCase(ismailinglist) = "true" Or LCase(ismailinglist) = "ismailinglist" Then
flags = (CLng(flags) Or ALIAS_LIST)
End If
Dim oUser
Set oUser = oUserCollection.AddAlias(user, _
emaillist, _
active, _
flags)
If oUser Is Nothing Then
WScript.Echo user & " has existed!"
Else
Dim oSettings
Set oSettings = oUser.PersonalSetting
Call oSettings.PutItem("description", description)
Call oSettings.PutItem("subscribe", subscribe)
Call oSettings.PutItem("unsubscribe", unsubscribe)
WScript.Echo "creating " & user & " succeeded!"
End If
End Sub
'========================================================
' fnTrim
'========================================================
Function fnTrim( Byref src, trimer )
Dim i, nCount, ch
nCount = Len(src)
For i = 1 To nCount
ch = Mid( src, i, 1 )
If InStr( 1, trimer, ch ) < 1 Then
Exit For
End If
Next
src = Mid( src, i )
nCount = Len(src)
For i = nCount To 1 Step -1
ch = Mid( src, i, 1 )
If InStr( 1, trimer, ch ) < 1 Then
Exit For
End If
Next
src = Mid( src, 1, i )
End Function
put both alias.csv and script at same folder, open command prompt at this folder, input cscript importaliasfromcsv.vbs systempassword yourdomain alias.csv run the following command, please change systempassword to your system password, also change your domain to domain name. Code:cscript importaliasfromcsv.vbs systempassword yourdomain alias.csv
|