Auto-generate "All Users" lists for each domain

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
Post Reply
C_Alden
New user
New user
Posts: 7
Joined: 2008-01-19 00:28

Auto-generate "All Users" lists for each domain

Post by C_Alden » 2008-01-29 01:34

This is a simple script I came up with to automatically generate distribution lists for all domains that will include all accounts in the domain. For best results (i.e. the most up-to-date list), it should be run as frequently as possible; I find that nightly suits our needs well enough.

Code: Select all

' hMailServer All Users List script
' Creates and maintains a distribution list that reaches all mailboxes
' By C. Alden

'Settings:

'Password for hMailServer Administrator
strAdminPassword = "password"

'Distribution List Name
strDistributionList = "AllUsers"


' ******************************************
' ***          Code starts here          ***
' ******************************************

' Create COM objects to interact with hMailServer
Set obBaseApp = CreateObject("hMailServer.Application")
obBaseApp.Authenticate "Administrator",strAdminPassword

intDomainCount = obBaseApp.Domains.Count

for i = 0 to (intDomainCount - 1)
	Set obDomain = obBaseApp.Domains.Item(i)
	Set obList = Nothing
	Set obRecipent = Nothing

	'See if list already exists; if so, delete it
	strListAddress = strDistributionList & "@" & obDomain.Name
	On Error Resume Next
	Set obList = obDomain.DistributionLists.ItemByAddress(strListAddress)
	On Error Goto 0
	
	If Not (obList Is Nothing) Then
		obList.Delete()
	End If

	Set obList = obDomain.DistributionLists.Add()
	obList.Address = strListAddress
	obList.Save()

	'Step through user accounts and add them to list
	intUserCount = obDomain.Accounts.Count
	For j = 0 to (intUserCount - 1)
		Set obRecipient = Nothing
		Set obAccount = obDomain.Accounts.Item(j)
		Set obRecipient = obList.Recipients.Add()
		obRecipient.RecipientAddress = obAccount.Address
		obRecipient.Save()
	Next
Next

User avatar
Pern
Normal user
Normal user
Posts: 46
Joined: 2006-09-07 21:14

Re: Auto-generate "All Users" lists for each domain

Post by Pern » 2011-01-12 23:21

works great thanks and works on hmailserver 5 too
Johnny - aka Pern
WebSite: dragonsworkshop.com ** Happy Holidays**

marceloleaes
New user
New user
Posts: 25
Joined: 2018-06-19 03:12

Re: Auto-generate "All Users" lists for each domain

Post by marceloleaes » 2018-06-19 03:15

It works perfectly

For my use only one resource was missing, I use the @ allusers groups but only one user can send to this group. Would it be possible to set this user in the list option via script?

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

Re: Auto-generate "All Users" lists for each domain

Post by mattg » 2018-06-19 08:09

Add one line between these two

obList.Address = strListAddress
obList.Save()



The line to add should be something like
obList.RequireSenderAddress = "sender@example.com"

This would make a single sender for ALL domains.
But then my question is why not use the 'server sendout' utility?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

marceloleaes
New user
New user
Posts: 25
Joined: 2018-06-19 03:12

Re: Auto-generate "All Users" lists for each domain

Post by marceloleaes » 2018-06-19 13:59

I did not really realize it would change for all domains ..
But for installations where there is only one domain will serve.

The send to all in Hmail you say?

This problem would release the user with admin from the domain ..

User avatar
jimimaseye
Moderator
Moderator
Posts: 7949
Joined: 2011-09-08 17:48

Re: Auto-generate "All Users" lists for each domain

Post by jimimaseye » 2018-06-19 15:16

I did a SERVERSENDOUT script for the individual domain here: viewtopic.php?p=179547#p179547
HMS 5.6.6 B2383 on Win Server 2008 R2 Foundation, + 5.6.7-B2415 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

Post Reply