Skip to main content
Version: 1.4

SMTP rules

SMTP rules decide during the SMTP conversation, before the message is sent, as cbpolicyd does on Zimbra. They refuse a client by where it connects from, a sender, a recipient or a whole message, and the Limit rules, on a page of their own, limit how much mail passes. A refused message is never received, so it costs no disk, no scanning and no bounce.

The other rule types work on the message once it is received. SMTP rules see only what the mail server knows at that point of the conversation, which is why each stage has its own rules.

The SMTP Rules - Connect page, with the buttons Add Rule, Actions, Move Up and Move Down, and the rule Reject not trusted with its Active switch

Stages​

StageAsked atWhat is knownA rule that matches refuses
ConnectThe client connectsWho connected and how: the client address and host name, and the portThe whole connection, every message on it
HELOHELO or EHLOAlso the HELO nameThe whole connection, every message on it
SenderMAIL FROMAlso the sender and the account the sender logged in withThe whole message, before any recipient
RecipientRCPT TO, once for each recipientAlso the recipientThat one recipient; the others still get the message
DataDATAEvery recipientThe whole message, before its content is sent

The Limit rules are asked at DATA too, after the rules of the Data stage, and refuse the whole message when it is over a limit.

Each stage is offered only the conditions whose value is known at that point: a Connect rule cannot ask for the sender, because the client has not sent it yet.

Postfix does not tell the client about a refusal at Connect or HELO right away: it keeps the connection open and gives the refusal at the client's MAIL FROM. The milter is not asked again on that connection.

How the rules of a stage run​

Every active rule of a stage runs, in the order of the list, until one refuses. The first refusal decides. There is no Next tab as in policy rules: what a rule must let through is one of its exceptions, for example the address list Trusted networks.

A recipient refused at the Recipient stage never becomes part of the message, so the message rules and the Message history never see it. Every refusal is listed on the SMTP Events page.

Switching SMTP rules off​

The Rules processing page has a switch SMTP rules, first in the list. While it is off, no SMTP rule refuses anything, and the stage pages say Processing of smtp rules is suspended. The Limit rules have a switch of their own, Limit rules, so the limits go on counting.

SMTP rules are part of Backup & Restore and reach every server with the other settings.

What SMTP rules need from the mail server​

Most of what SMTP rules ask for comes with the connection itself: the client address and host name, the HELO name, the sender and the recipients. The account the sender logged in with comes from the {auth_authen} macro, which Postfix sends with MAIL FROM by default. Locally injected mail (sendmail, non_smtpd_milters) has no client address, HELO name or login.

A value the mail server did not send never matches, and the processing trace says which one was missing, for example The mail server gave no HELO name. Not match.

How the client came in​

The condition Received through tells incoming mail (port 25), submission (ports 587 and 465) and webmail apart. It reads two macros Postfix sends when a client connects:

  • {daemon_name} - the milter_macro_daemon_name of the service. Zimbra sets it to ORIGINATING on its submission and 465 services, so on Zimbra nothing has to be done. Check it on each MTA server:

    sudo su - zimbra -c 'postconf -P' | grep milter_macro_daemon_name
  • {daemon_port} - the port the client connected to. Postfix does not send it by default. Add it when the submission services are not marked ORIGINATING, or when you use Another port in Received through:

    sudo su - zimbra -c 'postconf -e "milter_connect_macros = j {daemon_name} {daemon_addr} {daemon_port} v _"'
    sudo su - zimbra -c 'postfix reload'

    Zimbra rewrites the Postfix configuration from its own settings, so check after the next zmmtactl restart that postconf milter_connect_macros still lists {daemon_port}.

Without either macro, Received through matches nothing and the trace says The mail server did not say where the client connected: {daemon_name} and {daemon_port} are missing (add {daemon_port} to milter_connect_macros).

Webmail​

Zimbra's webmail hands mail to the MTA on port 25 from the mailbox server, without a login. Received through recognizes it as Mailbox server by the address list Mailbox servers: add the address of every mailbox server to it on the Address Lists page. Otherwise webmail counts as incoming mail from the internet.

A load balancer in front of Postfix​

A load balancer must pass the real client, or every rule on the client address sees only the balancer. With HAProxy, use send-proxy on the servers and, in Postfix, smtpd_upstream_proxy_protocol = haproxy on the service the balancer connects to (postscreen_upstream_proxy_protocol = haproxy when postscreen listens there).

Additional resources​