How to reject messages to unknown user in sendmail cooperating with MS-Exchange

filteringsendmailusers

I have an MS Exchange 2003 configured as a mail server for an organization. As this server is located in this organization internal network and I don't want to expose it directly over internet, I have second server – linux box with sendmail – configured as intelligent relay (it accept all messages from internet addressed to @my_domain, and forward it to internal Exchange serwer, and accepts all messages from this internal Exchange server and forward it over internet). This configuration work's fine, but I want to eliminate messages addressed to not exiting users as early as possible.

Good solution could be Enabling on Exchange server function of filtering recipients together with "tar pitting", but in my case this dosn't solve problem, because before any message reach my Exchange server (which could eventually reject it), it has to be already accepted by sendmail server, sitting in front of this Exchange server.

So, I want to configure my sendmail server in such a way, that during initial SMTP conversation it could query somehow my Exchange server checking whether recipient address is valid or not, and based on result of this query, accept or reject (possibly with some delay) incoming message in a very early phase.

In fact, I have already solved this issue by writing my own, simple sendmail milter program which checks recipient address against text file with list of valid addresses. But this solution is not satisfying me any longer, because it requires frequent updates of this file, and due to lack of time/motivation/programming skills, I don't want to cope further with my source code, adding to it functionality of querying my Exchange server.

Maybe I can achieve desired effect by configuring any component of already available linux software.

Any ideas?

Best Answer

You can keep your list up to date by querying Exchange (&(|(objectClass=group)(objectClass=user))(email=*)

through ldapsearch, or configure sendmail to lookup the incoming user through LDAP

define(confLDAP_DEFAULT_SPEC',-p 389 -h ldap.foobar.com' -b dc=foo,dc=bar'')dnl define(ALIAS_FILE',/etc/aliases,ldap:-k (&(|(objectclass=user)(objectclass=group))(proxyAddresses=smtp:%0)) -v mail')dnl

You'll need to adjust the LDAP_DEFAULT_SPEC line with appropriate parameters to search the proper OUs in your AD setup.

Caveats are the usual ones about what happens when your LDAP query fails (exchange / network is down) or is slow.