Instantiation of Application object

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Instantiation of Application object

Post by mikedibella » 2021-01-09 22:31

Is there an existing instantiation of the Application object, that is already authenticated, exposed within the event handlers and rule-triggered scripts? What is it's name?

Reason: My rule-triggered script need to access the parent Account for the oMessage message parameter, and access the parent Domain for the Account.

Code examples of same appreciated.

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

Re: Instantiation of Application object

Post by mattg » 2021-01-10 03:03

To ensure that I meet the Australian laws about logging specific detail, I write custom per-domain logs

Code: Select all

Function DomainLogging(oMessage)
	'custom event
	'uses functions: CustomMonthlyLog
	'uses globals: g_sAdminPassword
	'called from: Rules
	
	Dim i, j, oDomain, temptext, oApp, Local, tempDomain
	Set oApp = CreateObject("hMailServer.Application")

	' Give this script permission to access all
	' hMailServer settings.
	Call oApp.Authenticate("Administrator", g_sAdminPassword)

	tempDomain = Right(oMessage.FromAddress, Len(oMessage.FromAddress) - InStr(oMessage.FromAddress,"@"))
	Local = 0
	For i = 1 to oApp.domains.count
		if (InStr(1, tempDomain, oApp.Domains.item(i-1).name, 1) > 0) Then ' Local sender
			local = local + 1
			oDomain = tempDomain
		End If
		For j = 1 to oApp.Domains.item(i-1).DomainAliases.count
			if (InStr(1, tempDomain, oApp.Domains.item(i-1).DomainAliases.item(j-1).AliasName, 1) > 0) Then ' Local user.
				local = local + 1
				oDomain = oApp.Domains.Item(i-1).Name
			End If
		Next 'j
	Next 'i

	If Local > 0 Then 
		CustomMonthlyLog "", oDomain
		CustomMonthlyLog " New email from " & oMessage.FromAddress, oDomain
		CustomMonthlyLog "   Subject is:-" & oMessage.Subject, oDomain
		CustomMonthlyLog "   	Number of recipients is " & oMessage.Recipients.Count & _
			"  Number of Attachments is " & oMessage.Attachments.Count, oDomain
		For i = 1 To oMessage.Recipients.Count
			temptext = "       Recipient number " & i & " is " & oMessage.Recipients.Item(i-1).Address
			CustomMonthlyLog temptext, oDomain
		Next		
		For i = 1 To oMessage.Attachments.Count
			temptext = "       Attachment number " & i & " is " & oMessage.Attachments.Item(i-1).filename
			Call CustomMonthlyLog( temptext, oDomain)
		Next		
		CustomMonthlyLog "      Message size is:-" & oMessage.Size, oDomain
	End If
End Function
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply