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 email@example.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:
Refers to an entry from master.cf. If you are adding a new transport type, first create an entry for it in master.cf.
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.
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:
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.
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.
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.
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.
firstname.lastname@example.org 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.
220.127.116.11 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:
ondemand unix - - n - - smtp
defer_transports = ondemand
transport_maps = hash:/etc/postfix/transport
# postmap /etc/postfix/transport
# 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
18.104.22.168 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:
defer_transports = smtp
# 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.
General Configuration and Administration
Email and DNS
Local Delivery and POP/IMAP
Hosting Multiple Domains
Blocking Unsolicited Bulk Email
Transport Layer Security
Appendix A. Configuration Parameters
Appendix B. Postfix Commands
Appendix C. Compiling and Installing Postfix
Appendix D. Frequently Asked Questions