User Import

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
20721
New user
New user
Posts: 3
Joined: 2020-06-19 14:16

User Import

Post by 20721 » 2020-06-19 14:35

Hello dear community,
i'm pretty new to hmailserver and have already searched this but didn't really find what i'm looking for.
I use the program to get status messages from network devices via SMNP and forward them to external email addresses.
This works perfectly, but now we get MFP devices where scan-to-mail is used. So I have to create an account on the server for each user which forwards them to an external account.
Creating all users by hand would be a bit time consuming and I wanted to do this with a VBS script I found on the internet.
The script itself also works great when creating the accounts, but here the external email address and the forwarding is active.
I start the script myself with an Autoit script which passes the parameters to the VBS script until the list is processed accordingly, where the users are listed.

start hmail-create-accounts.vbs Username UserPW domain

Is there the possibility to extend this script so that I can use the parameters
for the external e-mail address and that it is active.
Enclosed the VBS Script

======================================

Code: Select all

Dim hmail, domain, account, email, noOfDomains, userName, userPassword, domainName, hMailAdminAccount, hMailAdminPassword

' These are the hMail admin account defaults after a silent install
hMailAdminAccount = "Administrator"
hMailAdminPassword = "Password"
'===============================================================
' No changes below this line
'===============================================================

' Check for account details from command line
If Wscript.Arguments.Count <> 3 Then
    WScript.Quit 1
End If

userName = Wscript.Arguments(0)
userPassword = Wscript.Arguments(1)
domainName = Wscript.Arguments(2)
'msgbox userName & " / " & userPassword & " @ " & domainName,0,"Input params"
email = userName & "@" & domainName

' Get connection to hMailServer
Set hmail = CreateObject("hMailServer.Application")
hmail.Authenticate hMailAdminAccount,hMailAdminPassword

' Check whether domain already exists
noOfDomains = hmail.Domains.Count
domainExists = false
if noOfDomains > 0 then
	for i = 0 to noOfDomains-1
		set domain = hmail.Domains.Item(i)
		if domain.Name = domainName then
			domainExists = true
			exit for
		end if
	next
end if

' Create domain if it does not yet exist
if domainExists = false then
	set domain = hmail.Domains.Add()
	domain.Name=domainName
	domain.Active=true
	domain.save()
end if

' Check whether account already exists
set accountList=domain.Accounts
noOfAccount = accountList.Count
accountExists = false
if noOfAccount > 0 then
	for i = 0 to noOfAccounts
		set account = accountList.Item(i)
		if account.Address = email then
			accountExists = true
			exit for
		end if
	next
end if

' Create account if it does not yet exist
if accountExists = false then
	set account=accountList.Add()
	account.Address=email
	account.Password=userPassword
	account.Active=true
	account.Forward=True
	account.Save()
end if
=========================================================

I would be happy about a positive answer or alternatives to the VBS file.

Translated with www.DeepL.com/Translator (free version)

User avatar
mattg
Moderator
Moderator
Posts: 21268
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: User Import

Post by mattg » 2020-06-20 01:28

like this - not tested

*** AND I REALLY HOPE THAT YOU DON'T USE THAT PASSWORD

Code: Select all

Dim hmail, domain, account, email, noOfDomains, userName, userPassword, domainName, hMailAdminAccount, hMailAdminPassword , ForwardToAddress

' These are the hMail admin account defaults after a silent install
hMailAdminAccount = "Administrator"
hMailAdminPassword = "Password"
'===============================================================
' No changes below this line
'===============================================================

' Check for account details from command line
If Wscript.Arguments.Count <> 4 Then
    WScript.Quit 1
End If

userName = Wscript.Arguments(0)
userPassword = Wscript.Arguments(1)
domainName = Wscript.Arguments(2)
ForwardToAddress = WScript.Arguments(3)
'msgbox userName & " / " & userPassword & " @ " & domainName,0,"Input params"
email = userName & "@" & domainName

' Get connection to hMailServer
Set hmail = CreateObject("hMailServer.Application")
hmail.Authenticate hMailAdminAccount,hMailAdminPassword

' Check whether domain already exists
noOfDomains = hmail.Domains.Count
domainExists = false
if noOfDomains > 0 then
	for i = 0 to noOfDomains-1
		set domain = hmail.Domains.Item(i)
		if domain.Name = domainName then
			domainExists = true
			exit for
		end if
	next
end if

' Create domain if it does not yet exist
if domainExists = false then
	set domain = hmail.Domains.Add()
	domain.Name=domainName
	domain.Active=true
	domain.save()
end if

' Check whether account already exists
set accountList=domain.Accounts
noOfAccount = accountList.Count
accountExists = false
if noOfAccount > 0 then
	for i = 0 to noOfAccounts
		set account = accountList.Item(i)
		if account.Address = email then
			accountExists = true
			exit for
		end if
	next
end if

' Create account if it does not yet exist
if accountExists = false then
	set account=accountList.Add()
	account.Address=email
	account.Password=userPassword
	account.Active=true
	account.Forward=True
	account.ForwardAddress=ForwardToAddress
	account.ForwardKeepOriginal=False
	account.Save()
end if
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

20721
New user
New user
Posts: 3
Joined: 2020-06-19 14:16

Re: User Import

Post by 20721 » 2020-06-21 14:21

Hello mattg,
of course it's not the password, but I didn't want to leave it blank either.
So I tested it today and also read through it.
If I start the script accordingly I get the feedback.

The object does not support this property or method: "Forward".

That you have to set DIm and the parameters should have been in my mind.

Code 800A0186
Source: Runtime error in Microsoft VBScript

User avatar
mattg
Moderator
Moderator
Posts: 21268
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: User Import

Post by mattg » 2020-06-21 15:06

It's meant to be ForwardEnabled not Forward sorry

Try this

Code: Select all

Dim hmail, domain, account, email, noOfDomains, userName, userPassword, domainName, hMailAdminAccount, hMailAdminPassword , ForwardToAddress

' These are the hMail admin account defaults after a silent install
hMailAdminAccount = "Administrator"
hMailAdminPassword = "Password"
'===============================================================
' No changes below this line
'===============================================================

' Check for account details from command line
If Wscript.Arguments.Count <> 4 Then
    WScript.Quit 1
End If

userName = Wscript.Arguments(0)
userPassword = Wscript.Arguments(1)
domainName = Wscript.Arguments(2)
ForwardToAddress = WScript.Arguments(3)
'msgbox userName & " / " & userPassword & " @ " & domainName,0,"Input params"
email = userName & "@" & domainName

' Get connection to hMailServer
Set hmail = CreateObject("hMailServer.Application")
hmail.Authenticate hMailAdminAccount,hMailAdminPassword

' Check whether domain already exists
noOfDomains = hmail.Domains.Count
domainExists = false
if noOfDomains > 0 then
	for i = 0 to noOfDomains-1
		set domain = hmail.Domains.Item(i)
		if domain.Name = domainName then
			domainExists = true
			exit for
		end if
	next
end if

' Create domain if it does not yet exist
if domainExists = false then
	set domain = hmail.Domains.Add()
	domain.Name=domainName
	domain.Active=true
	domain.save()
end if

' Check whether account already exists
set accountList=domain.Accounts
noOfAccount = accountList.Count
accountExists = false
if noOfAccount > 0 then
	for i = 0 to noOfAccounts
		set account = accountList.Item(i)
		if account.Address = email then
			accountExists = true
			exit for
		end if
	next
end if

' Create account if it does not yet exist
if accountExists = false then
	set account=accountList.Add()
	account.Address=email
	account.Password=userPassword
	account.Active=true
	account.ForwardEnabled=True
	account.ForwardAddress=ForwardToAddress
	account.ForwardKeepOriginal=False
	account.Save()
end if
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

20721
New user
New user
Posts: 3
Joined: 2020-06-19 14:16

Re: User Import

Post by 20721 » 2020-06-21 18:03

Hello megg,
it's going perfectly now.
I have modified it a little bit concerning the recipient address, because it didn't work out.
Now it works perfectly and I can write a script with AutoIT for about 200 users.

Code: Select all

Dim Forwarddomain, hmail, domain, account, email, noOfDomains, userName, userPassword, domainName, hMailAdminAccount, hMailAdminPassword , ForwardToAddress

' These are the hMail admin account defaults after a silent install
hMailAdminAccount = "Administrator"
hMailAdminPassword = "password"
'===============================================================
' No changes below this line
'===============================================================

' Check for account details from command line
If Wscript.Arguments.Count <> 5 Then
    WScript.Quit 1
End If

userName = Wscript.Arguments(0)
userPassword = Wscript.Arguments(1)
domainName = Wscript.Arguments(2)
ForwardToAddress = WScript.Arguments(3)
Forwarddomain = WScript.Arguments(4)
'msgbox userName & " / " & userPassword & " @ " & domainName,0,"Input params"
email = userName & "@" & domainName
extemail = ForwardToAddress & "@" & Forwarddomain

' Get connection to hMailServer
Set hmail = CreateObject("hMailServer.Application")
hmail.Authenticate hMailAdminAccount,hMailAdminPassword

' Check whether domain already exists
noOfDomains = hmail.Domains.Count
domainExists = false
if noOfDomains > 0 then
	for i = 0 to noOfDomains-1
		set domain = hmail.Domains.Item(i)
		if domain.Name = domainName then
			domainExists = true
			exit for
		end if
	next
end if

' Create domain if it does not yet exist
if domainExists = false then
	set domain = hmail.Domains.Add()
	domain.Name=domainName
	domain.Active=true
	domain.save()
end if

' Check whether account already exists
set accountList=domain.Accounts
noOfAccount = accountList.Count
accountExists = false
if noOfAccount > 0 then
	for i = 0 to noOfAccounts
		set account = accountList.Item(i)
		if account.Address = email then
			accountExists = true
			exit for
		end if
	next
end if

' Create account if it does not yet exist
if accountExists = false then
	set account=accountList.Add()
	account.Address=email
	account.Password=userPassword
	account.Active=true
	account.ForwardEnabled=True
	account.ForwardAddress=email2
	account.ForwardKeepOriginal=True
	account.Save()
end if
Thanks for your Help

Post Reply