averellen
  • averellen
  • 52.25% (Neutral)
  • Newbie Topic Starter
8 years ago
Is there a script that allows for mass import of Alias users?

These would be Lists, requiring the description set along with the subcribe and unsubscrib keywords set.



Thank you

ivan
  • ivan
  • 100% (Exalted)
  • Administration
8 years ago
CSV format is not good for alias, because address list and subscribe/unsubscribe keywords contains line-break. You can refer to installation path\webaccess\alias.asp which demonstrates how to create an alias.
Or could you send a sample CSV file to our support email address so that I can write a script to you.
averellen
  • averellen
  • 52.25% (Neutral)
  • Newbie Topic Starter
8 years ago
Thank you for the reply.

I only need the following items to be populated, the remaining isn't required for my test.

user,description,active,this alias is mailing list,subscribe keyword, unsubscribe keyword
list1@localhost,list 1 mailing list,enabled,ismailinglist,subscribe,unsubscribe
list2@localhost,list 2 mailing list,enabled,ismailinglist,subscribe,unsubscribe

ivan
  • ivan
  • 100% (Exalted)
  • Administration
8 years ago
please named your alias content as alias.csv


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



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.

cscript importaliasfromcsv.vbs systempassword yourdomain alias.csv

averellen
  • averellen
  • 52.25% (Neutral)
  • Newbie Topic Starter
8 years ago
Ivan

Worked like a charm thank you. Where would I find the elements for PutItem?

Adam
ivan
  • ivan
  • 100% (Exalted)
  • Administration
8 years ago
You can refer to installation path\webaccess\alias.asp, there are full items for alias in this file.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.