Transport Maps

Postfix can be configured to relay to any other host, regardless of how DNS MX records are set up. This section discusses the transport_maps parameter in general. Later sections and other chapters in the book present specific configurations that use it.

Conceptually, transport maps override default transport types for delivery of messages. The transport_maps parameter points to one or more transport lookup tables. The following entry sets up /etc/postfix/transport as a transport map lookup table:

transport_maps = hash:/etc/postfix/transport

The keys in a transport lookup table are either complete email addresses or domains and subdomains. (Email addresses as lookup keys for transport maps require Postfix 2.0 or later.) When a destination address or domain matches a lefthand key it uses the righthand value to determine the delivery method and destination. Example 9-1 lists some possible transport map entries.

Example 9-1. Transport map entries

example.com smtp:[192.168.23.56]:20025
oreilly.com relay:[gateway.oreilly.com]
oreillynet.com smtp
ora.com maildrop
kdent@ora.com error:no mail accepted for kdent

The format of righthand values can differ depending on the transport type, but generally has the form transport:nexthop, where nexthop often indicates a host and port for delivery. Each of the possible portions of the righthand value are described here:

transport

Refers to an entry from master.cf. If you are adding a new transport type, first create an entry for it in master.cf.

host

The destination host for delivery of messages. The host is used only with inet transports such as SMTP and LMTP. Postfix treats the hostname like any destination domain. It performs an MX lookup to determine where to deliver messages. If there are no MX records, Postfix delivers to the A record IP address. If you know that Postfix should deliver directly to the IP in the A record for the specified host, you can have Postfix skip the check for MX records by enclosing the name in brackets. If you use an IP address, the brackets are required.

port

The destination port for message delivery. The port is used only with inet transports such as SMTP and LMTP. The port can be specified using the actual number or its symbolic name from the /etc/services file.

Each of the sample entries from Example 9-1 uses a different format in their righthand values, which are explained below:

example.com smtp:[192.168.23.56]:20025

All messages destined for example.com are relayed using the smtp transport to the host at IP address 192.168.23.56. Messages are delivered over port 20025 instead of the default SMTP port 25. Notice that the IP address is in brackets, as required for IP addresses.

oreilly.com relay:[gateway.oreilly.com]

All messages destined for oreilly.com are relayed using the relay transport to the host gateway.oreilly.com. Since no port is specified, Postfix uses the default port 25. The hostname is in brackets to prevent Postfix from looking up MX records. Instead, it looks up the A record and delivers to the IP address that the hostname resolves to.

The relay transport was introduced in Version 2 of Postfix to fix a potential performance bottleneck with queue scheduling. You should direct inbound messages relayed to internal systems over the relay transport, so that they don't compete with messages destined for many different systems on the Internet.

oreillynet.com smtp

All messages destined for oreillynet.com are relayed using the smtp transport. Since both the next hop and port are left off, Postfix uses the default port 25 and determines the next hop based on the destination address. Most often, the next hop is determined by performing a DNS lookup, which determines the MX host for the domain. This example is a bit contrived, since simply listing oreillynet.com with relay_hosts achieves the same thing in this case.

ora.com maildrop

All messages destined for ora.com are delivered to the maildrop service. maildrop must be an entry in master.cf. Since delivery occurs over a pipe rather than an inet socket, no host and port are specified.

kdent@ora.com error:no mail accepted for kdent

The special error transport causes all mail to be rejected. After the colon, specify a message to report when email is rejected.

Transport maps can also be used for special handling of certain messages on the local system. (Chapter 14 discusses content filters, which provide a good example of configuring special local transports.) Another local use of transport maps is to temporarily defer all of a domain's messages. To demonstrate a simple use of transport maps, the next section describes a procedure to defer all of the messages for a domain.

9.2.1 Postponing Mail Delivery

Under some circumstances you want Postfix to postpone delivery of messages until it has received an explicit command to deliver them. Deferred messages are delivered when you issue the postqueue -f domain command or Postfix receives an ETRN SMTP command from a fastflush-eligible domain.

A common scenario for deferring messages is when an ISP receives mail for a customer network that is not always online. The ISP must queue messages until the network is online and can receive them. Similarly, users on the customer network should send messages through a local gateway that queues them until they can be delivered once the network is online. This section presents configurations for both situations.

9.2.1.1 Deferring mail relay

This procedure sets up a new transport type called "ondemand," and configures a transport map to defer all messages for the example.com domain:

  1. Create a new transport in your master.cf file called ondemand. It should be identical to your smtp transport except for the name:

    ondemand unix - - n - - smtp
  2. Tell Postfix that delivery of all messages over your new transport should be deferred automatically. Edit the defer_transports parameter in main.cf to include your ondemand transport:

    defer_transports = ondemand
  3. Make sure that the transport_maps parameter points to your transport lookup table:

    transport_maps = hash:/etc/postfix/transport
  4. Add an entry to your transport file for example.com that points it to the ondemand transport:

    example.com ondemand
  5. Execute postmap on the file.

    # postmap /etc/postfix/transport
  6. Reload Postfix so that it recognizes the changes in its configuration files:

    # postfix reload

Now any message destined for example.com is deferred until there is an explicit command to deliver it.

When you are ready to release the deferred messages, issue the postqueue -f command:

$ postqueue -f example.com

9.2.1.2 Deferring delivery

A home network or small office network that wants to trigger delivery manually should defer all SMTP deliveries, so that delivery attempts only occur when a connection to the Internet has been established:

  1. In main.cf, assign the smtp transport to the defer_transports parameter:

    defer_transports = smtp
  2. Reload Postfix so that it recognizes the changes in its configuration file:

    # postfix reload

Once a connection is established, all of the messages can be delivered using postqueue -f.

The rest of this chapter describes various scenarios where Postfix must relay mail to other systems. In many cases, transport maps are necessary for configuring the next-hop delivery details.





Postfix(c) The Definitive Guide
Postfix: The Definitive Guide
ISBN: 0596002122
EAN: 2147483647
Year: 2006
Pages: 130
Authors: Kyle Dent D.
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net