
procmail Command in Linux
The procmail command in Linux is an autonomous mail processor that automatically processes incoming email. It can be invoked through a .forward file, called by a mail transfer agent (MTA) like sendmail or postfix, or run manually. It reads mail from stdin, separates headers from the body, and applies rules from an rcfile like .procmailrc to determine the emailâs destination.
Table of Contents
Here is a comprehensive guide to the options available with the procmail command â
- Installation of procmail Command in Linux
- Syntax of procmail Command
- procmail Command Options
- Examples of procmail Command in Linux
Installation of procmail Command in Linux
The procmail command is often pre-installed on some distributions, if it is not installed, install it. To install it on Ubuntu, Kali Linux, Debian, and other Debian-based distributions, use the following command −
sudo apt install procmail
To install it on CentOS, use the following command −
sudo yum install procmail
To install it on Fedora, use the command given below −
sudo dnf install procmail
To verify the installation, check the version of procmail using the following command −
procmail -v

Syntax of procmail Command
The syntax of the procmail command in Linux is as follows −
procmail [options] [rcfile] [arguments]
In the above syntax −
- [options] − Control procmail behavior such as -p, -t, -m, or -v.
- [rcfile] − Specifies a custom rule file instead of the default .procmailrc.
- [arguments] − Additional inputs, such as recipient usernames (-d recipient).
procmail Command Options
The options of the Linux procmail command are listed below −
Option | Description |
---|---|
-v | Displays version and compile-time configuration. |
-p | Preserves environment variables except TZ. Overridden by default values. |
-t | Enables "soft failure" mode-mail is returned to the queue instead of bouncing. |
-f fromwhom | Sets the From line in the message. |
-o | Overrides fake From lines. |
-Y | Assumes traditional Berkeley mailbox format (ignores Content-Length). |
-a argument | Assigns arguments to $1 , $2 , etc., for use in recipes. |
-d recipient | Explicitly delivers mail to a local user (requires root privileges). |
-m | Runs procmail as a standalone mail filter using an rcfile. |
-z | Enables LMTP mode for direct mail delivery (RFC 2033). |
Examples of procmail Command in Linux
This section explores how to use the procmail command in Linux with examples −
- Processing an Email using Default procmailrc File
- Delivering an Email to a Specific Recipient
- Preserving the Environment Variable
- Handling Bounced Emails
- Processing an Email with the Specific Sender
- Using a Custom rcfile
- Display Usage Help
Processing an Email using Default procmailrc File
To process an email using the default procmailrc file, use the procmail command in the following way −
procmail < email
The above command reads the email file, applies rules from ~/.procmailrc (system-wide /etc/procmailrc), and delivers the email.
Delivering an Email to a Specific Recipient
To deliver an email to a specific recipient, use the -d option −
sudo procmail -d username < email
Preserving the Environment Variable
To preserve the environment variable while processing an email, use the -p option −
procmail -p < email
Handling Bounced Emails
To handle the failed emails with the soft failure mode, use the -t option. Instead of bouncing the email, it returns to the mail queue −
procmail -t < email
Processing an Email with the Specific Sender
To process an email with a specific sender, use the -f option. For example, the following command overrides the From line in the email header with sam@example.com −
procmail -f sam@example.com < email
Using a Custom rcfile
To specify the custom rcfile, use the -m option with the rcfile path −
procmail -m /path/to/rcfile < email
The -m option is used when procmail is invoked manually to filter messages through a custom rule file, often for integration with external scripts.
Display Usage Help
To display the usage help of the procmail command, use the -h option −
procmail -h

Conclusion
The procmail command in Linux is a powerful tool for processing and filtering emails automatically. It can be installed on various Linux distributions and used with different options to control email delivery, preserve environment variables, handle bounced emails, and apply custom filtering rules.
In this tutorial, we covered the procmail command, its installation, syntax, options, and usage in Linux with examples.