Replicate AD Proxy Addresses into hMailServer Route Address Tables

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

Replicate AD Proxy Addresses into hMailServer Route Address Tables

Post by mikedibella » 2016-12-10 21:40

I'm using hMailServer as a perimeter bridgehead for Exchange in a small implementation. I wanted a way to reject mail for invalid recipients so I came up with an approach to replicate the recipient proxy addresses from Active directory into the hMailServer route address table.

The solution consists to two scripts.

GetRecipients.asp is a classic ASP script that publishes an XML file containing all proxy-address for User and Contacts. Put this file in a virtual directory on an IIS server joined to the domain, with Classic ASP enabled, and configure for Basic Authentication over secure channel. There are a few query options to export proxy addresses for users only, users and contacts, or user, contacts and groups. The default is users and contacts. If everything is configured correctly, you should be able to point a browser at the URL for the file at get an authentication challenge. After providing credentials, an XML response should be returned.

SyncRoutes.vbs is a VBScript file that runs on the hMailserver. Put this file in the hMailServer bin directory. The are a few variables that must be set in the file to customize the configuration for your environment. Read the comments in the file and set the URL, username and password to retrieve the proxy address XML file, and the username and password to login to hMailServer. Schedule the file to run as a task using cscript.exe. An event will be logged in the Application log for each run.

SyncRoutes.vbs only syncs the route table for each domain under Settings | Protocols | SMTP | Routes. If you want to restrict deliver to the route table for each domain, you need change the option from "Deliver to all address" to "Deliver to addresses below".

My implementation is small and I haven't done any stress testing. GetRecipients uses an inefficient sort algorithm and SyncRoutes uses an iterative list reconciliation algorithm so processing times will increase with larger implementations.
Attachments
SyncRoutes.zip
(2.57 KiB) Downloaded 104 times

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

Re: Replicate AD Proxy Addresses into hMailServer Route Address Tables

Post by mikedibella » 2016-12-11 21:32

In further testing, I observed the Microsoft.XmlHttp COM control to cache responses. The update adds cache control headers to the response generated by GetRecipients.asp.
Attachments
SyncRoutes.zip
(2.56 KiB) Downloaded 97 times

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

Re: Replicate AD Proxy Addresses into hMailServer Route Address Tables

Post by mikedibella » 2016-12-11 22:55

GetRecipients.vbs: Changed Cache-Control from "no-cache" to "no-cache, no-store, must-revalidate".
Attachments
SyncRoutes.zip
(2.58 KiB) Downloaded 148 times

Post Reply