
pipe Command in Linux
In Linux, the pipe in Postfix is a delivery agent that helps send emails to external programs. It allows messages to be passed to custom scripts or tools like spam filters, logging systems, or special mail handlers. The master process of the Postfix controls the pipe service and works with the queue manager to process emails correctly. It can use macros to set details like the sender, recipient, and destination dynamically.
Table of Contents
Here is a comprehensive guide to the options available with the pipe command −
Syntax of Pipe Delivery Agent
The syntax for defining a pipe transport in Postfix is as follows −
transport unix - n n - - pipe user=username argv=command [arguments]
In the above syntax
- transport − The name of the delivery transport.
- user=username − Specifies the user under which the command will run.
- argv=command [arguments] − Defines the external command to execute and its arguments.
The pipe delivery agent is configured in the master.cf file.
Pipe Delivery Agent Options
Several attributes can be set in master.cf to control pipe behavior. General options are listed below −
Option | Description |
---|---|
chroot=pathname | Changes the process root directory. |
directory=pathname | Changes to the specified directory before execution. |
eol=string | Defines the end-of-line character (\n or \r\n). |
size=size_limit | Sets a maximum message size. |
user=username[:groupname] | Specifies the user (and optional group) for execution. |
argv=command... | Defines the external command. |
Processing flags modify the behavior of the pipe delivery agent. They are set using the flags= option in master.cf. A list of processing flags is given below −
Flag | Description |
---|---|
B | Appends a blank line to messages. |
D | Adds a Delivered-To: header and enforces loop detection. |
F | Adds a From sender timestamp envelope header. |
O | Adds an X-Original-To: header. |
R | Adds a Return-Path: header. |
X | Marks the message as finally delivered. |
h | Converts domain names to lowercase. |
q | Quotes special characters in addresses. |
u | Converts local parts of addresses to lowercase. |
. | Escapes lines starting with ... |
> | Escapes lines starting with From. |
Macros are placeholders that are replaced with actual values when the command runs. These are used in the argv= section of master.cf. Macros are listed below −
Macro | Description |
---|---|
${sender} | Expands to the envelope sender. |
${recipient} | Expands to the envelope recipient. |
${original_recipient} | Expands to the original recipient before aliasing. |
${client_address} | Expands to the remote client IP address. |
${client_hostname} | Expands to the remote client hostname. |
${nexthop} | Expands to the next-hop hostname. |
${size} | Expands to the message size. |
Examples of Pipe Delivery Agent in Linux
This section explains how to use the Postfix pipe delivery agent in Linux with an example.
Defining a UUCP-based Email Transport using the pipe Delivery Agent
To use the pipe for external processing, define a transport in the master.cf file located in the /etc/postfix directory. Open the file using the following command −
sudo nano /etc/postfix/master.cf
The following Postfix configuration defines a UUCP (Unix-to-Unix Copy Protocol) transport to send email messages to a remote system via UUCP −
uucp unix - n n - - pipe flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)

In the above example, uucp is the transport name, and unix is the transport type.
- | Default privileges | Runs with Postfix's default privileges. |
n | No chroot | Does not run in a chroot environment. |
n | No wakeup | Does not require periodic wakeups. |
- | No process limit | No specific limit on concurrent processes. |
- | Default command-line length | Uses the default command-line length limit. |
The pipe in the above example is the delivery agent which allows email to be passed to an external command specified with the argv field. The flags=Fqhu controls how the email is handled before execution. F passes the sender as the first argument, q ensures safe argument handling, h removes the "From " line, and u runs the command as uucp.
The user=uucp is the execution user which ensures that UUCP-related commands execute with appropriate permissions.
The transport is executing the following command −
argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
The above command queues the email for UUCP delivery. uux submits the job, -r prevents immediate execution, -n suppresses status messages, and -z disables job notifications. -a$sender sets the sender's address, - reads the email from standard input, $nexthop!rmail specifies the remote system and rmail for delivery, and ($recipient) sets the recipient's email address.
Mapping Transport
To map a transport, open the main.cf file using the following command −
sudo nano /etc/postfix/main.cf

Enable the mapping by adding the following line −
transport_maps = hash:/etc/postfix/transport

Now, define the transport rule in the transport file −
sudo nano /etc/postfix/transport
To route emails for mydomain.com through the UUCP transport, add this line −
mydomain.com uucp

Finally, update the transport database and restart the Postfix service −
sudo postmap /etc/postfix/transport sudo systemctl restart postfix
Conclusion
The Postfix pipe delivery agent allows seamless integration of external programs for email processing, supporting spam filters, logging tools, and custom handlers. It is configured in the master.cf file, where you can define transport settings, execution commands, and user permissions. Processing flags and macros allow customization of message handling and delivery. A practical example demonstrates its use with UUCP for remote email transmission. Mapping transport rules in main.cf further refines email routing.