Help with COM API

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
New user
New user
Posts: 1
Joined: 2022-05-08 00:43

Help with COM API

Post by scubabevo » 2022-05-08 01:30

We use hmailserver 5.3.3 as an email relay. I would like to use a script to rewrite the sender using the alias table. From what I have read COM API would be the best practice to pull data from the database. I need to pull aliasname and aliasvalue from hm_aliases. I assume I need something like this:

Dim obDB
Set obDB = CreateObject("hMailServer.Application")
Call obDB.Authenticate("Administrator","Password")
EventLog.Write("Past Authentication")

Dim obDomain
Set obDomain = ""

Dim obAliases
Set obAliases = obDomain.DomainAliases

Dim obAlias, i
for i = 0 to (obAliases.Count - 1)
Set obAlias=obAliases.Item(i)
EventLog.Write(obAlias.AliasValue + " " + obAlias.AliasName)
If LCase (obAlias.AliasValue) = LCase (oMessage.FromAddress) Then
oMessage.FromAddress = obAlias.AliasName
oMessage.From = obAlias.AliasName
Exit For
End If

Now I have noticed I get Past Authentication even if the password is wrong but I never get to in the logs but get the following error:

"ERROR" 4884 "2022-05-07 19:26:05.106" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01A8 - Description: Object required: '[string: ""]' - Line: 13 Column: 0 - Code: (null)"

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

Re: Help with COM API

Post by mattg » 2022-05-08 02:40

scubabevo wrote:
2022-05-08 01:30
We use hmailserver 5.3.3...

That version is more than 10 years out of date
Just 'cause I link to a page and say little else doesn't mean I am not being nice.

User avatar
Senior user
Senior user
Posts: 1032
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Help with COM API

Post by katip » 2022-05-08 05:58

try this:

Code: Select all

Set oDomains = oApp.Domains
Set oAliases = oDomains.ItemByName("").Aliases
For i = 0 to oAliases.Count -1
	If LCase (oAliases(i).Value) = LCase (oMessage.FromAddress) Then
		'do your things
	End If
and yes, consider upgrading your HMS.
HMS 5.7, MariaDB 10.4.10, SA 3.4.4, ClamAV 0.103.5

Post Reply