Name

bestmx

Synopsis

The bestmx database-map type looks up a hostname as the key and returns the current, single best MX record as the value. Because bestmx is a type, not a database map, you need to declare it with a K configuration command before you can use it:

Kbestmx bestmx

One use for this database-map type might be to see whether a particular host has any usable MX records:[10]

Kbestmx bestmx
...
R $*< @ $+ > $*                $: $1<@$2>$3 < $(bestmx $2 $: NO $) >
R $*< @ $+ > $* < NO >         $#smtp  $@ $2 $: $1 < @ $2 > $3
R $*< @ $+ > $* < $* >         $: $1<@ $[ $2 $] > $3

In the first rule we look up the host part of an address (which has already been focused by the canonify rule set 3) with the bestmx database map. The result of the lookup is surrounded with angle brackets and appended to the original address. The second rule looks for the NO caused by an unsuccessful lookup (the $:). The original address is then sent with the smtp delivery agent. If the hostname inside the appended angle braces is not NO, the host part of the original address is canonicalized with the $[ and $] operators.

bestmx is a special internal type that can utilize only a few of the K command switches, as listed in Table 23-8.

Table 23-8. The bestmx database-map type K command switches

Switch

§

Description

-a

-a

Append tag on successful match

-D

-D

Don’t use this database map if DeliveryMode=defer

-m

-m

Suppress replacement on match

-q

-q

Don’t strip quotes from key

-T

-T

Suffix to append on temporary failure ...

Get Sendmail, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.