FromAddress doesn't change properly.

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
Marco84IT
New user
New user
Posts: 2
Joined: 2021-11-15 12:23

FromAddress doesn't change properly.

Post by Marco84IT » 2021-11-15 17:29

Hello to everybody,

we are working with hMail (latest version) in order to create a "forward email system" internal on my company.
Only STMP functionalities are used (no IMAP, POP3). The system sends mails only (receives mails from clients and send to destination email servers)

Our company domain is: test.com
Our "hmail domain" is: out.test.com

Usually, we require to clients to send email with domain test.com while they have to authenticate with domain out.test.com (we have created many users, e.g user1@out.test.com, user2@out.test.com, ...)
Through scripts file we have been able to set some rules and restrict, for example, the FromAddress (e.g: user1@out.test.com can use only FromAddress "red@test.com").

We have some clients that are not able to set their FromAddress and they use, as FromAddress, the authentication user by default.
In this case we want help this users to set their FromAddress properly, so we want modify their FromAddress directly on the script.

This is an extract of our script:

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)


	If (oClient.Username = "user1@out.test.com") Then
	
		If (strcomp(oMessage.FromAddress, "user1@out.test.com") = 0) Then
			oMessage.FromAddress = "red@test.com"
			Result.value = 0
		End If

	End if

End Sub
Seems the script works properly, in the hMail log we see the FromAddress is changed (also in awstats the FromAddress is changed).

The problem is the destination receives the mail with original FromAddress (user1@out.test.com).

Could you please suggest where I'm wrong.
Really really thanks
Regards
Marco

User avatar
SorenR
Senior user
Senior user
Posts: 5016
Joined: 2006-08-21 15:38
Location: Denmark

Re: FromAddress doesn't change properly.

Post by SorenR » 2021-11-15 18:44

Marco84IT wrote:
2021-11-15 17:29
Hello to everybody,

we are working with hMail (latest version) in order to create a "forward email system" internal on my company.
Only STMP functionalities are used (no IMAP, POP3). The system sends mails only (receives mails from clients and send to destination email servers)

Our company domain is: test.com
Our "hmail domain" is: out.test.com

Usually, we require to clients to send email with domain test.com while they have to authenticate with domain out.test.com (we have created many users, e.g user1@out.test.com, user2@out.test.com, ...)
Through scripts file we have been able to set some rules and restrict, for example, the FromAddress (e.g: user1@out.test.com can use only FromAddress "red@test.com").

We have some clients that are not able to set their FromAddress and they use, as FromAddress, the authentication user by default.
In this case we want help this users to set their FromAddress properly, so we want modify their FromAddress directly on the script.

This is an extract of our script:

Code: Select all

Sub OnAcceptMessage(oClient, oMessage)


	If (oClient.Username = "user1@out.test.com") Then
	
		If (strcomp(oMessage.FromAddress, "user1@out.test.com") = 0) Then
			oMessage.FromAddress = "red@test.com"
			Result.value = 0
		End If

	End if

End Sub
Seems the script works properly, in the hMail log we see the FromAddress is changed (also in awstats the FromAddress is changed).

The problem is the destination receives the mail with original FromAddress (user1@out.test.com).

Could you please suggest where I'm wrong.
Really really thanks
Regards
Marco
You also need to change oMessage.From ...

oMessage.FromAddress equals "X-Envelope-From" and oMessage.From is the MIME "From".
SørenR.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- Douglas Adams

Marco84IT
New user
New user
Posts: 2
Joined: 2021-11-15 12:23

Re: FromAddress doesn't change properly.

Post by Marco84IT » 2021-11-20 18:00

Hi SorenR,

really thanks for your reply.

I edited my script:

Code: Select all

If (oClient.Username = user1@out.test.com) Then
	
		If (strcomp(oMessage.FromAddress, user1@out.test.com) = 0) Then
			oMessage.FromAddress = red@test.com
			oMessage.From = “red@test.com”
			oMessage.HeaderValue("X-Envelope-From") = red@test.com
			Result.value = 0
		End If

	End if
I don't understand what I have to do with the MIME. It has a specific from variable in hmail?

Regards
Marco

User avatar
SorenR
Senior user
Senior user
Posts: 5016
Joined: 2006-08-21 15:38
Location: Denmark

Re: FromAddress doesn't change properly.

Post by SorenR » 2021-11-20 22:22

FromAddress is sender address om the envelope om US Potage. MIME From is the senders signature in the letter.
SørenR.

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- Douglas Adams

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

Re: FromAddress doesn't change properly.

Post by mattg » 2021-11-21 00:48

Marco84IT wrote:
2021-11-20 18:00

Code: Select all

If (oClient.Username = user1@out.test.com) Then
	
		If (strcomp(oMessage.FromAddress, user1@out.test.com) = 0) Then
			oMessage.FromAddress = red@test.com
			oMessage.From = “red@test.com”
			oMessage.HeaderValue("X-Envelope-From") = red@test.com
			Result.value = 0
		End If

	End if
If you are changing values, you also need to do a save to make them stick
Do

oMessage.save

before the result.value line
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