Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
averellen  
#1 Posted : Wednesday, March 8, 2017 8:55:02 AM(UTC)
averellen

Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3

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  
#2 Posted : Sunday, March 12, 2017 6:42:48 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
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  
#3 Posted : Monday, March 13, 2017 9:55:28 AM(UTC)
averellen

Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3

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  
#4 Posted : Monday, March 13, 2017 11:07:54 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

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


averellen  
#5 Posted : Tuesday, March 14, 2017 6:50:51 AM(UTC)
averellen

Rank: Newbie

Groups: Registered
Joined: 3/8/2017(UTC)
Posts: 3

Ivan

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

Adam
ivan  
#6 Posted : Wednesday, March 15, 2017 5:23:36 AM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,154

Thanks: 9 times
Was thanked: 55 time(s) in 55 post(s)
You can refer to installation path\webaccess\alias.asp, there are full items for alias in this file.

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.210 seconds.

EXPLORE TUTORIALS

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