Change from address not working as expected

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
outrunner77
New user
New user
Posts: 5
Joined: 2019-04-30 12:10

Change from address not working as expected

Post by outrunner77 » 2019-05-07 11:18

Hi,

I’m trying to configure hmailserver to work as an outgoing relay and always change the from address, before sending on to an external relayer/smarthost, which will only accept messages sent from a specific secure address.

I’ve edited the eventhandelers script to always change oMessage.FromAddress and oMessage.From to the required address, but relaying a message only works when I send from the secure address. Sending from a different address the messages gets stuck in the queue.

As a test I changed hmailserver to forward to an internal IIS relay, which then sends the message on to the smarthost, and this seems to work. The from address is updated by hmilserver which then passes the messages to the IIS relay, which forwards to the smarthost and the message is delivered.

I have limited understanding of mailservers, but researching the issue I’m wondering if it has something to do with the smtp envelope sender, which is only updated correctly when introducing the extra hop.

So yeah, not sure if any of that makes any sense, but is there any way to do this all on the single hmailserver build?

Thanks

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

Re: Change from address not working as expected

Post by mattg » 2019-05-07 12:58

please show your eventhandlers.vbs

Mostly the from address will be changed by a 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

outrunner77
New user
New user
Posts: 5
Joined: 2019-04-30 12:10

Re: Change from address not working as expected

Post by outrunner77 » 2019-05-07 14:02

This is what I have in my script:

Sub OnAcceptMessage(oClient, oMessage)
oldFrom = oMessage.FromAddress
oMessage.FromAddress = "s.relay@mhs.net"
oMessage.From = "<s.relay@mhs.net>"
oMessage.save
EventLog.Write("Testing account From rewrite " & oldFrom & " - to - " & oMessage.FromAddress )
Result.value = 0
End Sub

Like I said it works, but only if I forward to another internal relay, which then sends to the smart host.

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

Re: Change from address not working as expected

Post by mattg » 2019-05-08 13:12

Try changing this line

oMessage.From = "<s.relay@mhs.net>"

to something like

oMessage.From = "Real Account <s.relay@mhs.net>"




This below code CREATES and sends an email when the backup is completed

Code: Select all

Sub OnBackupCompleted()
	dim oApp, sBackupLog, oMessage
	Set oApp = CreateObject("hMailServer.Application")
	Dim MessageRecipientName, MessageRecipientAddress, MessageSubject
	MessageRecipientName = "Server"
	MessageRecipientAddress = "server@example.com"
	MessageSubject = "Hmailserver Backup Completed"

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

	sBackupLog = ReadFileUnicode(oApp.Settings.Backup.LogFile)
	DeleteFile(oApp.Settings.Backup.LogFile)

	Dim BNFrom, BNFromAddress
	Set BNFrom = "hMailServer Backup"
	Set BNFromAddress = "server@example.com"

	Set oMessage = CreateObject("hMailServer.Message")
	oMessage.From = BNFrom & " <" & BNFromAddress &  ">"
	oMessage.FromAddress = BNFromAddress
	oMessage.Subject = MessageSubject
	oMessage.AddRecipient MessageRecipientName, MessageRecipientAddress
	oMessage.Body = "The backup completed successfully." & vbNewLine & vbNewLine & sBackupLog
	oMessage.Save
End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

outrunner77
New user
New user
Posts: 5
Joined: 2019-04-30 12:10

Re: Change from address not working as expected

Post by outrunner77 » 2019-05-09 15:48

Thanks for the reply, however, this is working now without me changing anything. I can only assume hmailserver required a couple of restarts to kick things into life.

Post Reply