Utility to set route to domain MX

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
mikedibella
Normal user
Normal user
Posts: 236
Joined: 2016-12-08 02:21

Utility to set route to domain MX

Post by mikedibella » 2019-10-04 00:48

I needed a way to bypass the smart relay for some domains and send mail for these domains directly to the mail exchanger in DNS.

A route in HMS will do this, but the Target SMTP Host must be statically defined. These hostnames change from time-to-time, and I wanted a way to keep the route up-to-date so it behaved more like traditional DNS-based MX delivery for that domain only.

hmsRouteMX.exe was written to update a specified route with the the lowest Preference Mail Exchanger published in DNS for the specified domain.

To use hmsRouteMX.exe, edit the appropriate .reg file for your OS and populate the Nameserver, Username, and Password fields with the DNS server, and credentials to access HMS. Change the Logging level (0-2) if you want more or less verbosity in the event log. Copy hmsRouteMX.exe to your hMailServer\Bin directory and schedule it to run using Task Scheduler, passing the route name as a parameter.

Written in Delphi. Source included. Requires The Indy Project libraries to compile. Freeware under The MIT License.
Attachments
hmsRouteMX.zip
(202.72 KiB) Downloaded 129 times

User avatar
jimimaseye
Moderator
Moderator
Posts: 8780
Joined: 2011-09-08 17:48

Re: Utility to set route to domain MX

Post by jimimaseye » 2019-10-04 09:05

Can you explain what you mean by
mikedibella wrote:
2019-10-04 00:48
IA route in HMS will do this, but the Target SMTP Host must be statically defined. These hostnames change from time-to-time, and I wanted a way to keep the route up-to-date so it behaved more like traditional DNS-based MX delivery for that domain only.
Camb you give an example please to better understand the purpose ?

[Entered by mobile. Excuse my spelling.]
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

mikedibella
Normal user
Normal user
Posts: 236
Joined: 2016-12-08 02:21

Re: Utility to set route to domain MX

Post by mikedibella » 2019-10-04 23:23

For example, an old MTA, which was the lowest Preference host, is retired, and the old backup MX gets promoted by having the new lowest Preference in DNS. Eventually, another MX is introduced, which might have a different hostname, or a higher Preference.

Or, multiple MX share the same Preference and the ordering of the hosts is round-robin'ed by DNS. Each time hmsRouteDNS.exe is run, a new query is made, resulting in a new MX bubbling-up to the top, so traffic then gets distributed across the hosts as the authority for that domain intended.

mfields
New user
New user
Posts: 9
Joined: 2016-05-06 14:56

Re: Utility to set route to domain MX

Post by mfields » 2020-09-07 10:58

jimimaseye wrote:
2019-10-04 09:05
Camb you give an example please to better understand the purpose ?
I would love to see this built into hMailServer.

Use case:
  • We use hMailServer for outbound email from our web applications, hence have to configure the domain we're sending email from in hMailServer.
  • There is a requirement for hMailServer to send email to recipients under the same domain we send email from, and emails are hosted elsewhere (such as O365 or G-Suite).
  • Currently have to configure a route and manually enter the MX address. Would instead prefer an option such as Don't try to deliver mail locally for this domain which would tell hMailServer to lookup the MX record via DNS and send as normal SMTP without requiring a route.

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

Re: Utility to set route to domain MX

Post by SorenR » 2020-09-07 13:31

mfields wrote:
2020-09-07 10:58
jimimaseye wrote:
2019-10-04 09:05
Camb you give an example please to better understand the purpose ?
I would love to see this built into hMailServer.

Use case:
  • We use hMailServer for outbound email from our web applications, hence have to configure the domain we're sending email from in hMailServer.
  • There is a requirement for hMailServer to send email to recipients under the same domain we send email from, and emails are hosted elsewhere (such as O365 or G-Suite).
  • Currently have to configure a route and manually enter the MX address. Would instead prefer an option such as Don't try to deliver mail locally for this domain which would tell hMailServer to lookup the MX record via DNS and send as normal SMTP without requiring a route.
So ... You do know that there are two sets of addresses in an email ... Envelope addresses and content addresses ... Just like when we did korrespondance written on paper and stuck it into an envelope ... The envelope would say "to the tennant of apt. 41B" and on the back "from Building administration" and looking at the letter inside the envelope it would say "To John Doe" and signed "Frank Zappa, building manager"

Now the envelope addressing is the "Recipient = most often derived from the To:" and the sender is the credentials you authenticated with on hMailServer.
INSIDE the envelope you have your mail headers "To:", "Cc:" and "From:" and those you can put ANY ADDRESSES in. hMailServer don't really care about them, hMailServer only care about the envelope for delivery.

In reality it is with very little efford possible to logon as "carrot-top@la-la.land" on domain "la-la.land" and send an email To: "road.runner@acme.inc" From: "wile.e.coyote@acme.inc" Cc: "taz@looney.tunes".

ALTERNATIVE ...
Create acme.inc on hMailServer, create acme.inc on O365, define route on hMailServer TO acme.inc on O365, create "sender@acme.inc" ONLY on hMailServer and start sending mail to "anyone@acme.inc" and see what happens ... ;-)
SørenR.

" I will initiate self-destruct. " — IG-11.

Post Reply