During an SMTP conversation, a client introduces itself to a server using the HELO or EHLO command. The standard does not specify what should be said here, and many Windows clients in fact use a "bogus" name: for instance, the domain name of the destination server. Nevertheless, it may sometimes be useful to check the argument to HELO/EHLO, as many SPAM programs use bogus arguments in a consistent manner.

In a very helpful e-mail, a sendmail maintainer explained to me how this could be done. The trick is to use delayed macro expansion with the $s macro. As the sendmail manual explains, $s is a transient macro: at startup, when sendmail reads its configuration file, it contains the name of the host on which sendmail runs, but during an SMTP conversation, it expands into the hostname supplied by the remote client as the argument to HELO/EHLO. By writing $&s, it is possible to delay the expansion of this macro, so it is expanded only when it is needed; e.g., during Local_check_rcpt.

Consequently, my sendmail.mc file contains a local rule set similar to the following (note that Local_check_rcpt, if exists, is automatically called by sendmail at the appropriate stage of processing the envelope):

SLocal_check_rcpt
R$*			$: $&s
Rbogus.domain		$#error $: 550 Spam Forbidden\ ($&s)
R$*			$@ OK