Domains in an array?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
segamegadave
New user
New user
Posts: 15
Joined: 2011-10-20 18:11

Domains in an array?

Post by segamegadave » 2011-11-15 14:09

Hi,

I currently have a script (which somebody else wrote but I amended) which checks outgoing mails to see if the @domain in the from address matches the @domain of the authorised user. I am trying to amend this script so that for each mail sent instead of checking whether it matches the the @domain of the authorised user it instead checks that the domain exists on the system.

Unfortuantly my scripting is poor and although I know what it needs to do I'm not quite sure how to get there. Can anyone give me any clues as to how to get all hmailservers local domains into an array and then how to check for a values existence in the array?

I have searched through the forums to try and find this but with no luck.

Current script:

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
    'checks the from address on the email and if the @domain does not match the @domain of the authorised user then a report will be sent to support@domain.com
	If oClient.Username <> "" Then
        dim authemail, authemail_value, fromemail, fromemail_value, reportuser, reportfromaddress
        
		reportuser = oClient.Username
		reportfromaddress = oMessage.FromAddress
		reportfrom = oMessage.From
		
		authemail = Split ( (oClient.Username) , "@" )
        authemail_value = authemail(1)

        fromemail = Split ( (oMessage.FromAddress) , "@" )
        fromemail_value = fromemail(1)

        If LCase(authemail_value) <> LCase(fromemail_value) Then
    
			Set oMessage = CreateObject("hMailServer.Message")
			oMessage.From = "server@domain.com"
			oMessage.AddRecipient "support@domain.com", "support@domain.com"
			oMessage.Subject = "Incorrect Usage" 
			oMessage.Body = oMessage.Body & "User " & reportuser &  " has sent a mail from " & reportfrom & " using the from address " & reportfromaddress & vbCrLf & vbCrLf
			oMessage.Save
         
			set oMessage = nothing
        End If
    End If
	
End Sub
Many thanks in advance for any replys.
hMailServer 5.3.3,
Server 2008 R2 Standard
Xeon 2.8ghz
1gb RAM
IIS 7 with Roundcube 0.5.1

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

Re: Domains in an array?

Post by mattg » 2011-11-15 15:23

segamegadave wrote: I am trying to amend this script so that for each mail sent instead of checking whether it matches the the @domain of the authorised user it instead checks that the domain exists on the system.
You will need to create an instance of the hMailserver application object, and then access the domains one at a time, probably load them into an array and check the passed domain of the message against the contents of this array.

Here is an example http://www.hmailserver.com/documentatio ... ain_enable

If you can't script, then you should pay someone who can. :wink:
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

cncJasonB
New user
New user
Posts: 7
Joined: 2011-12-05 21:41

Re: Domains in an array?

Post by cncJasonB » 2011-12-05 22:12

mattg wrote:If you can't script, then you should pay someone who can. :wink:
It would be really helpful if there were a listing somewhere of people interested in contracted / commissioned scripting specific to hMailServer. Does a list like this exist somewhere?

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

Re: Domains in an array?

Post by mattg » 2011-12-07 14:48

I think I actually modified the script to achieve what you want since your original post :mrgreen:
I also check for domain aliases.

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)
	dim oApp, i, j, Local

	Set oApp = CreateObject("hMailServer.Application")

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

	Local = 0
	For i = 1 to oApp.domains.count
		if (InStr(1, oMessage.FromAddress, "@" & oApp.Domains.item(i-1).name, 1) > 0) Then ' Local user.
			local = local + 1
		End If
		For j = 1 to oApp.Domains.item(i-1).DomainAliases.count
			if (InStr(1, oMessage.FromAddress, "@" & oApp.Domains.item(i-1).DomainAliases.item(j-1).AliasName, 1) > 0) Then ' Local user.
				local = local + 1
			End If
		Next 'j
	Next 'i
	If local >0 then
		If (oClient.Username = "") Then
			Result.Value = 2
			Result.Message = "You must be authenticated to send from local domain."
		End If
	End If

End Sub
What this script does is check if the sender is from a local domain (any local domain!!) and ensures that if so, that the user authenticates (with any account) first
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