Previous Section Next Section

bestmx

Look up the best MX record for a host V8.7 and above

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:[9]

[9] We are digging at straws here for an example. Note that sendmail already does all this, including looking up more than just the first MX record.

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

-t

-t

Ignore temporary errors

-z

-z

Specify the column delimiter

The -z switch (special for this bestmx database-map type) allows multiple MX records to be returned, and specifies a column delimiter used to separate one record from another. So long as the column delimiter is not a character that appears in any domain name, it will be used to separate all the MX records returned by the MX lookup. These records will be returned in the new workspace. For example, if the -z switch specified a comma, and if abc.com were looked up, the following might be returned:

mail11 . disney . com . , mail . disney . com .

If the -z switch wrongly specifies a character that can exist in a domain name (such as a dot), the following error will be reported, and only one MX record will be returned:

bestmx_map_lookup: MX host mail11.disney.com. includes map delimiter character 0x2E

If too many MX records are returned, the list can be truncated to avoid an overly long workspace. When the list is truncated, some MX records can be lost. This can become a serious problem when this -z switch is used with this database-map type and when the relay_based_on_MX feature is also declared (Section 7.4.4).

This type can be watched with the -d8 debugging switch (-d8.1).

Previous Section Next Section