SCRIPT check if the sender accountid exist before sent the message

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
afrisoftsolutions
New user
New user
Posts: 1
Joined: 2020-07-17 20:47

SCRIPT check if the sender accountid exist before sent the message

Post by afrisoftsolutions » 2020-07-17 21:28

Hello to every body i'm using hmail server ver 5.6.6.B2383 and have lot of spams sending using my domain name
in the hmail i have the domin ddd.com and i have 5 accounts let says 1@ddd.com, ...5@ddd.com
but when i checking on the logs i seeing that they are mails sending from unknow@ddd.com

i need an solution because i have tried script for hmailser 4 but it's not working.
working with hmailserver more than 5 years

User avatar
johang
Senior user
Senior user
Posts: 448
Joined: 2008-09-01 09:20

Re: SCRIPT check if the sender accountid exist before sent the message

Post by johang » 2020-07-17 23:48

afrisoftsolutions wrote:
2020-07-17 21:28
Hello to every body i'm using hmail server ver 5.6.6.B2383 and have lot of spams sending using my domain name
in the hmail i have the domin ddd.com and i have 5 accounts let says 1@ddd.com, ...5@ddd.com
but when i checking on the logs i seeing that they are mails sending from unknow@ddd.com

i need an solution because i have tried script for hmailser 4 but it's not working.
working with hmailserver more than 5 years
set "Require SMTP authentication" for "Local to external e-mail addresses" on ALL needed IPranges
(go into [Settings][Advanced][IP Ranges] and set for all IP ranges ... everyone should authenticate )

since you only write they are using your domain name to send spam i guess you already have "Require SMTP authentication" for "External to external e-mail addresses"


or you can play with scripts
viewtopic.php?p=68117#p68117
___________________________________________________________end of the line

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

Re: SCRIPT check if the sender accountid exist before sent the message

Post by mattg » 2020-07-19 03:50

ALSO need to set 'require auth' for local to local connections
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

much_r
New user
New user
Posts: 11
Joined: 2020-04-01 14:50

Re: SCRIPT check if the sender accountid exist before sent the message

Post by much_r » 2020-09-30 17:59

Hi,

I have a very old software which cannot use SMTP authentication ...
That's why I activate a certain IP range for sending mail without authentication :( .
To narrow it down I only want to allow existing accounts to send mails

Please excuse my English :oops:

Thank you
Michael

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

Re: SCRIPT check if the sender accountid exist before sent the message

Post by mattg » 2020-09-30 23:23

Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

much_r
New user
New user
Posts: 11
Joined: 2020-04-01 14:50

Re: SCRIPT check if the sender accountid exist before sent the message

Post by much_r » 2020-10-01 10:59

Hello,

my colleague and I were able to find a solution for us.
Here is my entire script.
1. Allow only send from your own account, mailadress
2. Check if user exist
3. Rewrite FROM: or add Username to FROM:, For example if the sender is empty

Maybe someone can help

Regards
Michael

Code: Select all

Option Explicit
Private const g_sAdminPassword = "PASSWORD"

'   Sub OnClientConnect(oClient)
'   End Sub

'   Sub OnSMTPData(oClient, oMessage)
'   End Sub

'   Sub OnAcceptMessage(oClient, oMessage)
'   End Sub

'   Sub OnDeliveryStart(oMessage)
'   End Sub

'   Sub OnDeliverMessage(oMessage)
'   End Sub

'   Sub OnBackupFailed(sReason)
'   End Sub

'   Sub OnBackupCompleted()
'   End Sub

'   Sub OnError(iSeverity, iCode, sSource, sDescription)
'   End Sub

'   Sub OnDeliveryFailed(oMessage, sRecipient, sErrorMessage)
'   End Sub

'   Sub OnExternalAccountDownload(oFetchAccount, oMessage, sRemoteUID)
'   End Sub


' Allow only send from your own account, mailadress
' Check if user exist
' Rewrite FROM: or add Username to FROM:
Sub OnAcceptMessage(oClient, oMessage)

' Allow only send from your own account, mailadress
	dim oApp, i, j, Local, oldFrom, newFrom

	Set oApp = CreateObject("hMailServer.Application")

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

	If oClient.Username <> "" Then
		If LCase(oClient.Username) <> LCase(oMessage.FromAddress) Then
	 		Result.Value = 2
			Result.Message = "You are only allowed to send from your own account"
		End If
	End If
	
' Check if user exist  
    Local = 0
    For i = 1 to oApp.domains.count
        For j = 1 to oApp.Domains.item(i-1).Accounts.count
            if (StrComp(oMessage.FromAddress, oApp.Domains.item(i-1).Accounts.item(j-1).Address, 1) = 0) Then
                local = local + 1
            End If
        Next
    Next
    If local = 0 then
        If (oClient.Username = "") Then
            Result.Value = 2
            Result.Message = "Username not found"
        End If
    End If

' Rewrite FROM: or add Username to FROM:, For example if the sender is empty
	If oClient.Username <> "" Then
		If LCase(oClient.Username) = LCase(oMessage.FromAddress) Then
			oldFrom = oMessage.FromAddress
			newFrom = oClient.Username
			oMessage.FromAddress = newFrom
			oMessage.From = newFrom
			EventLog.Write("Rewrite from " & oldFrom & " - to - " & newFrom )
			oMessage.save
			Result.value = 0
		End If
	End If

End Sub

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

Re: SCRIPT check if the sender accountid exist before sent the message

Post by mattg » 2020-10-01 11:28

much_r wrote:
2020-10-01 10:59
Maybe someone can help
Help with what?

Is there a problem with your script?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

much_r
New user
New user
Posts: 11
Joined: 2020-04-01 14:50

Re: SCRIPT check if the sender accountid exist before sent the message

Post by much_r » 2020-10-02 21:32

No no, everything is ok. No problem. Thank you

I want to help should someone have the same requirement

Thanks and Greetings

Post Reply