This document describes the various steps of how a message flows through an on-premise mail server running on ClearOS. There are quite a few apps that can be involved in this process:
As you will soon find out reading this document, Postfix and Mail Routing are heavily involved in managing the mail flow. So let's get started.
An inbound message to ClearOS is first handled by the Postfix SMTP server running on TCP port 25. On arrival, the SMTP server does a few very basic tasks:
If the message is not bounced, it is delivered to the next stage in the mail process: Greylisting.
If Greylisting app is installed and running, the SMTP Server will hand off the message to the Postgrey greylist system. We will skip the details on greylisting, but you read more about it here. Once the message gets through the greylist engine, it is passed back to the Postfix SMTP Server.
The next step in the mail flow is “pre-filtering”, which is a script that is part of the “Mail Routing” core app. You won't see this app in Marketplace, it is just a library used by antivirus, antispam and other apps. The “pre-filter” is basically a traffic cop: it probes the system to see what is available and directs mail in the right direction. Specifically, if any of the following apps are installed, the pre-filter will hand off the mail message:
If none of the above apps are active, the pre-filter script will simply send the message back to the Postfix SMTP Server. If one or more of the above apps are active, the pre-filter script passes the message on to another traffic cop - the Mail Filter app (amavisd-new).
Once a message is received by the open source amavisd-new package, the software dispatches the message to other mail apps:
Viruses are discarded, spam is tagged or deleted, and suspicious messages are quarantined. If a message makes it through the labyrinth of Amavis mail processing, it is delivered back into the Postfix SMTP Server. For those command line hackers out there, the /etc/postfix/master.cf contains configuration for a special SMTP Server running on port 10026 (localhost only). Any mail delivered to this port skips over the mail filtering process and goes straight to the next step - preparing for final mail delivery.
After Mail Filter processing, the Postfix SMTP Server receives the mail message… again! At this point, the message is prepared for delivery. Specifically, if a message is addressed to multiple recipients, Postfix will create a copy of the message for each recipient. In addition, mail aliases and distribution lists are processed. The same thing happens here - a copy of the message is created for every valid recipient.
Before Postfix passes the message to the delivery system, the message goes through one last filter: the post-filter in the Mail Routing app.
Like its evil twin, mail “post-filter” is also a script that is part of the “Mail Routing” app. The “post-filter” can do things like detect a calendar event and take some kind of action. When the filter is complete, it passes the message on to the delivery system.
The last step in the mail flow is the actual mail delivery. Both Cyrus IMAP and Zarafa include delivery agents for this purpose. The “post-filter” connects to the delivery agent and the IMAP server handles the rest. search?q=clearos%2C%20clearos%20content%2C%20dev%2C%20architecture%2C%20maintainer_dloper&btnI=lucky