Can you create a Distribution List from CSV ???

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
AJB111
Normal user
Normal user
Posts: 184
Joined: 2005-01-28 05:13
Location: Australia
Contact:

Can you create a Distribution List from CSV ???

Post by AJB111 » 2005-10-25 08:38

Hi

Does anyone know of or have a script or easy method to import in a new distribution list from a csv or txt file?

TIA, John
Windows Server 2003, IIS6
HMail Server 5.3.1 B1748
MySQL 5.0.67

AJB111
Normal user
Normal user
Posts: 184
Joined: 2005-01-28 05:13
Location: Australia
Contact:

Post by AJB111 » 2005-11-15 00:42

*bump*

I assume this is something nobody has done by the lack of response, however, will try one last time ...

If anybody has done this or know how it could be done, would really appreciate the help

Thanks, John

User avatar
matty
Senior user
Senior user
Posts: 330
Joined: 2005-08-22 16:29
Location: New York
Contact:

Post by matty » 2005-11-15 05:55

You could probably write a vb script to import the values from a csv using the hmailserver COM object.
From the documentation of the Domain Object:
Property DistributionLists As DistributionLists
Returns a collection containing the distribution lists connected to this domain.
http://www.hmailserver.com/documentatio ... com_domain

I am guessing there is a DistributionList object but it does not seem to be in the documentation. Martin, is there any documentation on that? I assume you can add a new distribution list to this collection for the domain.

AJB111
Normal user
Normal user
Posts: 184
Joined: 2005-01-28 05:13
Location: Australia
Contact:

Post by AJB111 » 2005-11-16 22:28

Thanks Matty ...
matty wrote:is there any documentation on that? I assume you can add a new distribution list to this collection for the domain.
Martin, when you have some spare time, is this possible / available ?
Windows Server 2003, IIS6
HMail Server 5.3.1 B1748
MySQL 5.0.67

User avatar
martin
Developer
Developer
Posts: 6837
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-11-16 22:30

Do you know VBA ajb111?

AJB111
Normal user
Normal user
Posts: 184
Joined: 2005-01-28 05:13
Location: Australia
Contact:

Post by AJB111 » 2005-11-16 22:33

No real well myself Martin, but my partner is proficient with VBA ...

User avatar
martin
Developer
Developer
Posts: 6837
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-11-16 22:42

Before 4.2, the COM API will be documented. Shouldn't take more than an hour to create a script that does it then.

If you want to get started right away, you can use any type library browser to see which objects, method and properties are available in the API. I think pretty much all development environments can do this. Here's a free one. Just tested it quickly, looks like it does the job.

http://www.itripoli.com/itlv.asp

AJB111
Normal user
Normal user
Posts: 184
Joined: 2005-01-28 05:13
Location: Australia
Contact:

Post by AJB111 » 2005-11-16 22:47

Thanks Martin, will go and have a look immediately

Kind regards, John

neo
New user
New user
Posts: 7
Joined: 2006-06-12 16:43

create list members with SQL scripts

Post by neo » 2006-06-12 16:54

Hi,
You can add members in a distribution list with the sql scripts.

Ex: Import in the second list of the first domain, all accounts of the first domain.
-----------------------------------------
INSERT INTO hmailserver.hm_distributionlistsrecipients (`distributionlistrecipientlistid`,`distributionlistrecipientaddress`)
select 2, accountaddress
from hmailserver.hm_accounts
where accountdomainid=1;
-----------------------------------------

here:
2 is the second distribution list, and
1 is the first domain in hmail.

p.s. I used "SQL creator2" like sql administrator
By the way, don't use Hmail Administrator in the same time with SQL creator :D

neo
New user
New user
Posts: 7
Joined: 2006-06-12 16:43

Another way of importing members od Users, aliases &DLre

Post by neo » 2006-06-13 17:07

Another way of importing members od Users, aliases & Distribution List recipients:
Steps:
1. All is made: domain & distribution lists
2.Execute the script (Import.vbs) with the parameters in the file (Parameters.csv)

Here are the 2 files:

------------------
Import.vbs
-----------------------------------------------------
Option Explicit

Dim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewLine,i

Const ForReading = 1

Set obBaseApp = CreateObject("hMailServer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("Parameters.csv", ForReading)

Do While objTextFile.AtEndOfStream <> True
strNewLine = split(objTextFile.Readline, ",")

Select Case strNewLine(0)
Case "User"
AddUser strNewLine(1), strNewLine(2), strNewLine(3)
Case "Alias"
AddAlias strNewLine(1), strNewLine(2), strNewLine(3)
Case "DistributionListRecipient"
AddDistributionListRecipient strNewLine(1), strNewLine(2), strNewLine(3)
End Select

i = i + 1
Loop

Sub AddAlias(strAlias,strEmailAddress,strDomain)
Dim obDomain
Dim obAliases
Dim obNewAlias

Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
Set obAliases = obDomain.Aliases
Set obNewAlias = obAliases.Add()

obNewAlias.Name = strAlias & "@" & strDomain 'username
obNewAlias.Value = strEmailAddress 'password
obNewAlias.Active = 1 'activates user
obNewAlias.Save() 'saves account

Set obNewAlias = Nothing
Set obAliases = Nothing
Set obDomain = Nothing

End Sub

Sub AddUser(strUsername, strPassword, strDomain)
Dim obDomain
Dim obAccounts
Dim obNewAccount

Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
Set obAccounts = obDomain.Accounts
Set obNewAccount = obAccounts.Add()

obNewAccount.Address = strUsername & "@" & strDomain 'username
obNewAccount.Password = strPassword 'password
obNewAccount.Active = 1 'activates user
obNewAccount.Maxsize = 0 'sets mailbox size, 0=unlimited
obNewAccount.Save() 'saves account

Set obNewAccount = Nothing
Set obDomain = Nothing
Set obAccounts = Nothing

End Sub

Sub AddDistributionListRecipient(strRecipientAddress, strRecipientListAddress, strDomain)
Dim obDomain
Dim obDistributionLists
Dim obDistributionList
Dim obDistributionListRecipients
Dim obNewDistributionListRecipient

Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
Set obDistributionLists = obDomain.DistributionLists
Set obDistributionList = obDistributionLists.ItemByAddress(strRecipientListAddress & "@" & strDomain)
Set obDistributionListRecipients = obDistributionList.Recipients
Set obNewDistributionListRecipient = obDistributionListRecipients.Add()

obNewDistributionListRecipient.RecipientAddress = strRecipientAddress & "@" & strDomain 'recipientAddress
obNewDistributionListRecipient.Save() 'saves distributionListRecipient

Set obNewDistributionListRecipient = Nothing
Set obDistributionListRecipients = Nothing
Set obDistributionList = Nothing
Set obDistributionLists = Nothing
Set obDomain = Nothing


End Sub
-----------------------------------------------------


------------------
Parameters.csv
-----------------------------------------------------
User,blaze,mypassword1,mydomain.fr
User,blaze.miladinov,mypassword2,mydomain.fr
Alias,blazemiladinov,blaze@mydomain.fr,mydomain.fr
Alias,miladinovblaze,blaze@mydomain.fr,mydomain.fr
DistributionListRecipient,blaze,administrateurs,mydomain.fr
DistributionListRecipient,blaze.miladinov,administrateurs,mydomain.fr

-----------------------------------------------------

neo
New user
New user
Posts: 7
Joined: 2006-06-12 16:43

Post by neo » 2006-06-13 17:11

and thanks a Martin for "itripoli"....

davidm@imcu.com
New user
New user
Posts: 7
Joined: 2009-02-11 22:41

Re: Can you create a Distribution List from CSV ???

Post by davidm@imcu.com » 2009-02-12 17:16

I get this when running the import.vbs to create distribution lists:
Script: C:\import.vbs
Line: 54
Char: 1
Error: You do not have access to this property / method. Ensure that hMailServer.Application.Authenticate() is called with proper login credentials.
Code: 800403E9
Source: hMailServer COM Library


I think I saw this in another script where you have to pass the password for administrator to the script or hard code it but I don't remember the verbage...

bkeneu
New user
New user
Posts: 6
Joined: 2011-08-04 09:46

Re: Can you create a Distribution List from CSV ???

Post by bkeneu » 2011-09-07 21:35

Thank you this script saved me hours and hours of work.

swcheater
New user
New user
Posts: 3
Joined: 2016-02-29 11:45

Re: Can you create a Distribution List from CSV ???

Post by swcheater » 2016-03-02 16:57

i have the same error message: you don't have access to this property / method. Ensure that hMail.Server.Application.Authenticate is called with proper login credentials. Error in line 77 symbol 1. Can some one helps me?

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

Re: Can you create a Distribution List from CSV ???

Post by jimimaseye » 2016-03-02 18:46

Modified. Should now work. Change your Hmailserver administrator password on line 6.

Code: Select all

-----------------
Import.vbs
-----------------------------------------------------
Option Explicit
Dim HMSpassword

HMSpassword = "secretpassword"

Dim obBaseApp
Dim objFSO
Dim objTextFile
Dim strNewLine,i
Const ForReading = 1

Set obBaseApp = CreateObject("hMailServer.Application")
Call obBaseApp.Authenticate("Administrator", HMSpassword )

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("Parameters.csv", ForReading)

Do While objTextFile.AtEndOfStream <> True
   strNewLine = split(objTextFile.Readline, ",")

   Select Case strNewLine(0)
      Case "User"
         AddUser strNewLine(1), strNewLine(2), strNewLine(3)
      Case "Alias"
         AddAlias strNewLine(1), strNewLine(2), strNewLine(3)
      Case "DistributionListRecipient"
         AddDistributionListRecipient strNewLine(1), strNewLine(2), strNewLine(3)
   End Select
   i = i + 1
Loop

Sub AddAlias(strAlias,strEmailAddress,strDomain)
   Dim obDomain
   Dim obAliases
   Dim obNewAlias

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obAliases = obDomain.Aliases
   Set obNewAlias = obAliases.Add()

   obNewAlias.Name = strAlias & "@" & strDomain 'username
   obNewAlias.Value = strEmailAddress 'password
   obNewAlias.Active = 1 'activates user
   obNewAlias.Save() 'saves account

   Set obNewAlias = Nothing
   Set obAliases = Nothing
   Set obDomain = Nothing

End Sub

Sub AddUser(strUsername, strPassword, strDomain)
   Dim obDomain
   Dim obAccounts
   Dim obNewAccount

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obAccounts = obDomain.Accounts
   Set obNewAccount = obAccounts.Add()

   obNewAccount.Address = strUsername & "@" & strDomain 'username
   obNewAccount.Password = strPassword 'password
   obNewAccount.Active = 1 'activates user
   obNewAccount.Maxsize = 0 'sets mailbox size, 0=unlimited
   obNewAccount.Save() 'saves account

   Set obNewAccount = Nothing
   Set obDomain = Nothing
   Set obAccounts = Nothing

End Sub

Sub AddDistributionListRecipient(strRecipientAddress, strRecipientListAddress, strDomain)
   Dim obDomain
   Dim obDistributionLists
   Dim obDistributionList
   Dim obDistributionListRecipients
   Dim obNewDistributionListRecipient

   Set obDomain = obBaseApp.Domains.ItemByName(strDomain)
   Set obDistributionLists = obDomain.DistributionLists
   Set obDistributionList = obDistributionLists.ItemByAddress(strRecipientListAddress & "@" & strDomain)
   Set obDistributionListRecipients = obDistributionList.Recipients
   Set obNewDistributionListRecipient = obDistributionListRecipients.Add()

   obNewDistributionListRecipient.RecipientAddress = strRecipientAddress & "@" & strDomain 'recipientAddress
   obNewDistributionListRecipient.Save() 'saves distributionListRecipient

   Set obNewDistributionListRecipient = Nothing
   Set obDistributionListRecipients = Nothing
   Set obDistributionList = Nothing
   Set obDistributionLists = Nothing
   Set obDomain = Nothing
End Sub
5.7 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

swcheater
New user
New user
Posts: 3
Joined: 2016-02-29 11:45

Re: Can you create a Distribution List from CSV ???

Post by swcheater » 2016-03-03 20:42

jimimaseye wrote:Modified. Should now work. Change your Hmailserver administrator password on line 6.
thanks a lot dude

Post Reply