change external Accounts from Textfile

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
New user
New user
Posts: 1
Joined: 2018-02-06 21:30

change external Accounts from Textfile

Post by thoenny » 2018-02-22 23:20

Hi all,

I had the issue, that our ISP changed his mail configuration and we had to change the pop3 hostname and the users passwords in all th 238 external accounts of our hmail installation. I found some useful postings here like (thanks to percepts, jimimaseye, Bladeinger, Bill48105 and others....):

Since my day as a programmer are long ago (BASIC on a VC20, Pascal on Apple and some sort of C, C++ on Unix) I was glad to have some kind of templates here that helped me. I coded something, that was suitable in my situation (each account has exactly one external account, for example), but it worked for me and perhaps somebody else has the same issue and some programming professionals can correct/improve the code:

Code: Select all

'vbs script to update external accounts from a textfile into hmail server
'C. Thönny
'inspired by percepts, jimimaseye, Bladeinger, Bill48105 and others....
' see
' and

Dim user
Dim domain
Dim password 
Dim tmp
Dim obDomain
Dim obAccount
Dim obExtAccount  
Dim c 
 Dim obApp
   Set obApp = CreateObject("hMailServer.Application")
   Call obApp.Authenticate("superuser", "extremlytopsecretpassword")
   ' get the text file with data, make sure it exists
   Set obFSO=CreateObject("Scripting.FileSystemObject")
   Set obTextFile=obFSO.OpenTextFile("C:\scripts\mails.csv",1)
   ' open a log file for writing, make sure, it exists
   Set obLogFile=obFSO.OpenTextFile("c:\scripts\hmailtest.log",2)
   ' process the data file and count the data lines
   MsgBox("Beginning ....")
   Do while obTextFile.AtEndOfStream <> True
		obLogFile.Write("Dataset "&c&":"&"user: "&user&"@"&domain&" pass:" &password &"----------")
		'process the data:
		'Locate the domain we want to add the account to
		Set obDomain = obApp.Domains.ItemByName(domain)
		On Error Resume Next 
		Set obAccount = obDomain.Accounts.ItemByAddress(data(0))
		if err.number <> 0 then 
			obLogFile.Writeline("FAIL, probably doesn't exist in hmail Accounts? ")
			Set obExtAccount=obAccount.FetchAccounts.Item(0)
			if StrComp(obExtAccount.username,data(0)) <> 0 then obLogFile.Write("---------------------------------------------CAUTION, Missmatch of Account and external Account:" & obAccount.Address)
			'do something else like:
			obLogFile.Writeline("Success External Account " & obExtAccount.Username)
		end if 
	obLogFile.WriteLine("Ready, processed "& c & " external Accounts")	
	MsgBox(" ... ready. That's all, folks")

any improvements appreciate :-)

Post Reply