Change Header details for Sent emails only

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
mrbtamp2018
New user
New user
Posts: 14
Joined: 2019-07-29 12:47

Change Header details for Sent emails only

Post by mrbtamp2018 » 2019-08-06 06:28

Hmailserver is configured with a domain 'domain' having a account 'X.domain', which receives mails from external pop3 account and sends mail through through SMTP route configured with same external account.

This account 'X.domain' has 4 aliases A.domain,B.domain,C.domain,D.domain.

Outlook is configured with alias account names with main email address as 'X.domain'.

Now, when sending emails, the recipients receive the alias names in their message headers i.e FROM, REPLY-TO, RETURN-PATH.

If the recipient tries to reply to these mails, it would be delivered to alias accounts which does not exist.

So I tried to modify the message header under 'OnDeliverMessage' eventhandler vbscript.

Following is the code

Sub OnDeliverMessage(oMessage)
oMessage.HeaderValue("From") = "X.domain"
oMessage.HeaderValue("FromAddress") = "X.domain"
oMessage.HeaderValue("Reply-To") = "X.domain"
oMessage.HeaderValue("Return-Path") = "X.domain"
oMessage.save()
Result.Value=0
End Sub

But this changes headers for all the messages, received as well as sent.

What modification to the above code is needed to restrict the header changes to sent messages only Or is there any better way to handle this situation.

Kindly Suggest

User avatar
katip
Senior user
Senior user
Posts: 673
Joined: 2006-12-22 07:58
Location: Istanbul

Re: Change Header details for Sent emails only

Post by katip » 2019-08-06 10:58

assuming your senders do authenticate to send emails, you can distinguish local outbound messages from external incoming with for example:

Sub OnAcceptMessage(oClient, oMessage)
If oClient.Username <> "" Then... (i.e. this is from a local user)

alternatively, you can try global rules (Criteria : From contains xyz, Action -> Set Header value)
HTH
Katip
--
HMS 5.7.0-B2428-LTS-64-bit, MySQL 5.7.24, SA 3.4.2, ClamAV 0.101.2 + SaneS

hmailer24
New user
New user
Posts: 1
Joined: 2018-12-22 13:24

Re: Change Header details for Sent emails only

Post by hmailer24 » 2019-08-08 19:12

Hi,
i want to achieve similar thing, emails that are sent via my server (via authorized/whitelisted) hosts (my webservers) and change the from/to address.
The reason is that my docker containers are not configured FQDNs and this results in from/to addresses like application@5der3sdf5 (there is no domain ending).
I have configured rules already, but it seems they are not applied. Are rules applied when there is direct SMTP sending via the server?

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

Re: Change Header details for Sent emails only

Post by mattg » 2019-08-09 05:16

hmailer24 wrote:
2019-08-08 19:12
The reason is that my docker containers are not configured FQDNs
I see an easy fix there

hmailer24 wrote:
2019-08-08 19:12
I have configured rules already, but it seems they are not applied.
Please enable all logging in hmailserver, and send a message, then after 30 seconds show all logs created
hmailer24 wrote:
2019-08-08 19:12
Are rules applied when there is direct SMTP sending via the server?
Er... what other kind of sending is there?
hMailserver accepts SMTP connections, and messages received this way should have rules applied

Perhaps I don't understand your question
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