xref: /netbsd-src/external/ibm-public/postfix/dist/html/MILTER_README.html (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2        "http://www.w3.org/TR/html4/loose.dtd">
3
4<html>
5
6<head>
7
8<title>Postfix before-queue Milter support </title>
9
10<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
11
12</head>
13
14<body>
15
16<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix before-queue Milter support </h1>
17
18<hr>
19
20<h2>Introduction</h2>
21
22<p> Postfix implements support for the Sendmail version 8 Milter
23(mail filter) protocol. This protocol is used by applications that
24run outside the MTA to inspect SMTP events (CONNECT, DISCONNECT),
25SMTP commands (HELO, MAIL FROM, etc.) as well as mail content
26(headers and body).  All this happens before mail is queued.  </p>
27
28<p> The reason for adding Milter support to Postfix is that there
29exists a large collection of applications, not only to block unwanted
30mail, but also to verify authenticity (examples: <a
31href="http://www.opendkim.org/">OpenDKIM</a> and <a
32href="http://www.trusteddomain.org/opendmarc/">DMARC </a>)
33or to digitally sign mail (example: <a
34href="http://www.opendkim.org/">OpenDKIM</a>).
35Having yet another Postfix-specific version of all that software
36is a poor use of human and system resources. </p>
37
38<p> The Milter protocol has evolved over time, and different Postfix
39versions implement different feature sets.  See the <a
40href="#workarounds">workarounds</a> and <a
41href="#limitations">limitations</a> sections at the end of this
42document for differences between Postfix and Sendmail implementations.
43</p>
44
45<p> This document provides information on the following topics: </p>
46
47<ul>
48
49<li><a href="#plumbing">How Milter applications plug into Postfix </a>
50
51<li><a href="#building">Building Milter applications</a>
52
53<li><a href="#running">Running Milter applications</a>
54
55<li><a href="#config">Configuring Postfix</a>
56
57<li><a href="#workarounds">Workarounds</a>
58
59<li><a href="#limitations">Limitations</a>
60
61</ul>
62
63<h2><a name="plumbing">How Milter applications plug into Postfix </a> </h2>
64
65<p> The Postfix Milter implementation uses two different lists of
66mail filters: one list of filters for SMTP mail only,
67and one list of filters for non-SMTP mail. The two
68lists have different capabilities, which is unfortunate.  Avoiding
69this would require major restructuring of Postfix. </p>
70
71<ul>
72
73<li> <p> The SMTP-only filters handle mail that arrives via the
74Postfix <a href="smtpd.8.html">smtpd(8)</a> server. They are typically used to filter unwanted
75mail and to sign mail from authorized SMTP clients. You specify
76SMTP-only Milter applications with the <a href="postconf.5.html#smtpd_milters">smtpd_milters</a> parameter as
77described in a later section.  Mail that arrives via the Postfix
78<a href="smtpd.8.html">smtpd(8)</a> server is not filtered by the non-SMTP filters that are
79described next. </p>
80
81<li> <p> The non-SMTP filters handle mail that arrives via the
82Postfix <a href="sendmail.1.html">sendmail(1)</a> command-line or via the Postfix <a href="qmqpd.8.html">qmqpd(8)</a> server.
83They are typically used to digitally sign mail only. Although
84non-SMTP filters can be used to filter unwanted mail, they have
85limitations compared to the SMTP-only filters. You specify non-SMTP
86Milter applications with the <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a> parameter as described
87in a later section.  </p>
88
89</ul>
90
91<p> For those who are familiar with the Postfix architecture, the
92figure below shows how Milter applications plug into Postfix.  Names
93followed by a number are Postfix commands or server programs, while
94unnumbered names inside shaded areas represent Postfix queues.  To
95avoid clutter, the path for local submission is simplified (the
96<a href="OVERVIEW.html">OVERVIEW</a> document has a more complete description of the Postfix
97architecture).  </p>
98
99<blockquote>
100
101<table>
102
103<tr>
104
105<td colspan="2"> </td>
106
107<td align="center"> SMTP-only <br> filters </td>
108
109<td> </td>
110
111<td align="center"> non-SMTP <br> filters </td>
112
113</tr>
114
115<tr>
116
117<td colspan="2"> </td>
118
119<td align="center"> <table> <tr> <td align="center">
120^<br> <tt> | </tt> </td> <td align="center"> <tt> |<br> v </tt>
121</td> </tr> </table> </td>
122
123<td rowspan="2"> </td>
124
125<td rowspan="3" align="center"> <table> <tr> <td align="center">
126^<br> <tt> |<br> |<br> | </tt> </td> <td align="center"> <tt> |<br>
127|<br> |<br> v </tt> </td> </tr> </table> </td>
128
129</tr>
130
131<tr>
132
133<td> Network </td> <td> <tt> -&gt; </tt> </td>
134
135<td bgcolor="#f0f0ff" align="center" valign="middle"> <a href="smtpd.8.html">smtpd(8)</a>
136</td>
137
138</tr>
139
140<tr>
141
142<td colspan="3"> </td> <td> <tt> \ </tt> </td>
143
144</tr>
145
146<tr>
147
148<td> Network </td> <td> <tt> -&gt; </tt> </td>
149
150<td bgcolor="#f0f0ff" align="center" valign="middle"> <a href="qmqpd.8.html">qmqpd(8)</a>
151</td>
152
153<td> <tt> -&gt; </tt> </td>
154
155<td bgcolor="#f0f0ff" align="center" valign="middle"> <a href="cleanup.8.html">cleanup(8)</a>
156</td>
157
158<td> <tt> -&gt; </tt> </td>
159
160<td bgcolor="#f0f0ff" align="center" valign="middle"> <a
161href="QSHAPE_README.html#incoming_queue"> incoming </a> </td>
162
163</tr>
164
165<tr>
166
167<td colspan="3"> </td> <td> <tt> / </tt> </td>
168
169</tr>
170
171<tr>
172
173<td colspan="2"> </td>
174
175<td bgcolor="#f0f0ff" align="center" valign="middle"> <a href="pickup.8.html">pickup(8)</a>
176</td>
177
178</tr>
179
180<tr> <td colspan="2"> </td> <td align="center"> : </td> </tr>
181
182<tr>
183
184<td> Local </td> <td> <tt> -&gt; </tt> </td>
185
186<td bgcolor="#f0f0ff" align="center" valign="middle"> <a href="sendmail.1.html">sendmail(1)</a>
187</td>
188
189</tr>
190
191</table>
192
193</blockquote>
194
195<h2><a name="building">Building Milter applications</a></h2>
196
197<p> Milter applications have been written in C, JAVA and Perl, but
198this document deals with C applications only.   For these, you need
199an object library that implements the Sendmail 8 Milter protocol.
200Postfix currently does not provide such a library, but Sendmail
201does. </p>
202
203<p> Some
204systems install the Sendmail libmilter library by default.  With
205other systems, libmilter may be provided by a package (called
206"sendmail-devel" on some Linux systems).  </p>
207
208<p> Once libmilter is installed, applications such as <a
209href="http://www.opendkim.org/">OpenDKIM</a> and
210<a href="http://www.trusteddomain.org/opendmarc/">OpenDMARC</a>
211build out of the box without requiring any tinkering:</p>
212
213<blockquote>
214<pre>
215$ <b>gzcat opendkim-<i>x.y.z</i>.tar.gz | tar xf -</b>
216$ <b>cd opendkim-<i>x.y.z</i></b>
217$ <b>./configure ...<i>options</i>...</b>
218$ <b>make</b>
219[...<i>lots of output omitted</i>...]
220$ <b>make install</b>
221</pre>
222</blockquote>
223
224<h2><a name="running">Running Milter applications</a></h2>
225
226<p> To run a Milter application, see the documentation of the filter
227for options.  A typical command looks like this:</p>
228
229<blockquote>
230<pre>
231# <b>/some/where/opendkim -l -u <i>userid</i> -p inet:<i>portnumber</i>@localhost ...<i>other options</i>...</b>
232</pre>
233</blockquote>
234
235<p> Please specify a <i>userid</i> value that isn't used for other
236applications (not "postfix", not "www", etc.). </p>
237
238<h2><a name="config">Configuring Postfix</a></h2>
239
240<p> Like Sendmail, Postfix has a lot of configuration options that
241control how it talks to Milter applications. Besides global options
242that apply to all Milter applications, Postfix 3.0 and later
243support per-Milter timeouts, per-Milter error handling, etc. </p>
244
245<p> Information in this section: </p>
246
247<ul>
248
249<li><a href="#smtp-only-milters">SMTP-Only Milter applications </a>
250
251<li><a href="#non-smtp-milters">Non-SMTP Milter applications </a>
252
253<li><a href="#errors">Milter error handling </a>
254
255<li><a href="#version">Milter protocol version</a>
256
257<li><a href="#timeouts">Milter protocol timeouts</a>
258
259<li><a href="#per-milter">Different settings for different Milter
260applications </a>
261
262<li><a href="#macros">Sendmail macro emulation</a>
263
264<li><a href="#send-macros">What macros will Postfix send to Milters?</a>
265
266</ul>
267
268<h3><a name="smtp-only-milters">SMTP-Only Milter applications</a></h3>
269
270<p>  The SMTP-only Milter applications handle mail that arrives via
271the Postfix <a href="smtpd.8.html">smtpd(8)</a> server. They are typically used to filter
272unwanted mail, and to sign mail from authorized SMTP clients.  Mail
273that arrives via the Postfix <a href="smtpd.8.html">smtpd(8)</a> server is not filtered by the
274non-SMTP filters that are described in the next section. </p>
275
276<blockquote> NOTE for Postfix versions that have a <a href="postconf.5.html#mail_release_date">mail_release_date</a>
277before 20141018: do not use the <a href="header_checks.5.html">header_checks(5)</a> IGNORE action to remove
278Postfix's own Received: message header. This causes problems with
279mail signing filters. Instead, keep Postfix's own Received: message
280header and use the <a href="header_checks.5.html">header_checks(5)</a> REPLACE action to sanitize
281information. </blockquote>
282
283<p> You specify SMTP-only Milter applications (there can be more
284than one) with the <a href="postconf.5.html#smtpd_milters">smtpd_milters</a> parameter.  Each Milter application
285is identified by the name of its listening socket; other Milter
286configuration options will be discussed in later sections.  Milter
287applications are applied in the order as specified, and the first
288Milter application that rejects a command will override the responses
289from other Milter applications.  </p>
290
291<blockquote>
292<pre>
293/etc/postfix/<a href="postconf.5.html">main.cf</a>:
294    # Milters for mail that arrives via the <a href="smtpd.8.html">smtpd(8)</a> server.
295    # See below for socket address syntax.
296    <a href="postconf.5.html#smtpd_milters">smtpd_milters</a> = inet:localhost:<i>portnumber</i> ...<i>other filters</i>...
297</pre>
298</blockquote>
299
300<p> The general syntax for listening sockets is as follows: </p>
301
302<blockquote>
303
304<dl>
305
306<dt> <b>unix:</b><i>pathname</i> </dt> <dd><p>Connect to the local
307UNIX-domain server that is bound to the specified pathname. If the
308<a href="smtpd.8.html">smtpd(8)</a> or <a href="cleanup.8.html">cleanup(8)</a> process runs chrooted, an absolute pathname
309is interpreted relative to the Postfix queue directory.</p> </dd>
310
311<dt> <b> inet:</b><i>host</i><b>:</b><i>port</i> </dt> <dd> <p>
312Connect to the specified TCP port on the specified local or remote
313host.  The host and port can be specified in numeric or symbolic
314form.</p>
315
316<p> NOTE: Postfix syntax differs from Milter syntax which has the
317form <b>inet:</b><i>port</i><b>@</b><i>host</i>. </p>  </dd>
318
319</dl>
320
321</blockquote>
322
323<h3> <a name="non-smtp-milters">Non-SMTP Milter applications </a> </h3>
324
325<p> The non-SMTP Milter applications handle mail that arrives via
326the Postfix <a href="sendmail.1.html">sendmail(1)</a> command-line or via the Postfix <a href="qmqpd.8.html">qmqpd(8)</a>
327server. They are typically used to digitally sign mail. Although
328non-SMTP filters can be used to filter unwanted mail, there are
329limitations as discussed later in this section.  Mail that arrives
330via the Postfix <a href="smtpd.8.html">smtpd(8)</a> server is not filtered by the non-SMTP
331filters.  </p>
332
333<p> NOTE: Do not use the <a href="header_checks.5.html">header_checks(5)</a> IGNORE action to remove
334Postfix's own Received: message header. This causes problems with
335mail signing filters. Instead, keep Postfix's own Received: message
336header and use the <a href="header_checks.5.html">header_checks(5)</a> REPLACE action to sanitize
337information. </p>
338
339<p> You specify non-SMTP Milter applications with the <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a>
340parameter. This parameter uses the same syntax as the <a href="postconf.5.html#smtpd_milters">smtpd_milters</a>
341parameter in the previous section. As with the SMTP-only filters,
342you can specify more than one Milter application; they are applied
343in the order as specified, and the first Milter application that
344rejects a command will override the responses from the other
345applications.  </p>
346
347<blockquote>
348<pre>
349/etc/postfix/<a href="postconf.5.html">main.cf</a>:
350    # Milters for non-SMTP mail.
351    # See below for socket address syntax.
352    <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a> = inet:localhost:<i>portnumber</i> ...<i>other filters</i>...
353</pre>
354</blockquote>
355
356<p> There's one small complication when using Milter applications
357for non-SMTP mail: there is no SMTP session.  To keep Milter
358applications happy, the Postfix <a href="cleanup.8.html">cleanup(8)</a> server actually has to
359simulate the SMTP client CONNECT and DISCONNECT events, and the
360SMTP client EHLO, MAIL FROM, RCPT TO and DATA commands. </p>
361
362<ul>
363
364<li> <p> When new mail arrives via the <a href="sendmail.1.html">sendmail(1)</a> command line,
365the Postfix <a href="cleanup.8.html">cleanup(8)</a> server pretends that the mail arrives with
366ESMTP from "localhost" with IP address "127.0.0.1". The result is
367very similar to what happens with command line submissions in
368Sendmail version 8.12 and later, although Sendmail uses a different
369mechanism to achieve this result.  </p>
370
371<li> <p> When new mail arrives via the <a href="qmqpd.8.html">qmqpd(8)</a> server, the Postfix
372<a href="cleanup.8.html">cleanup(8)</a> server pretends that the mail arrives with ESMTP, and
373uses the QMQPD client hostname and IP address. </p>
374
375<li> <p> When old mail is re-injected into the queue with "postsuper
376-r", the Postfix <a href="cleanup.8.html">cleanup(8)</a> server uses the same client information
377that was used when the mail arrived as new mail. </p>
378
379</ul>
380
381<p> This generally works as expected, with only one exception:
382non-SMTP filters must not REJECT or TEMPFAIL simulated RCPT TO
383commands.  When a <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a> application REJECTs or TEMPFAILs
384a recipient, Postfix will report a configuration error, and mail
385will stay in the queue.  </p>
386
387<h4> Signing internally-generated bounce messages </h4>
388
389<p> Postfix normally does not apply content filters to mail
390that is generated internally such as bounces or Postmaster
391notifications. Filtering internally-generated bounces would result
392in loss of mail when a filter rejects a message, as the resulting
393double-bounce message would almost certainly also be blocked. </p>
394
395<p>  To sign Postfix's own bounce messages, enable filtering of
396internally-generated bounces (line 2 below), and don't reject any
397internally-generated bounces with <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a>, <a href="postconf.5.html#header_checks">header_checks</a>
398or <a href="postconf.5.html#body_checks">body_checks</a> (lines 3-5 below).  </p>
399
400<blockquote>
401<pre>
4021 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
4032     <a href="postconf.5.html#internal_mail_filter_classes">internal_mail_filter_classes</a> = bounce
4043     <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a> = <i>don't reject internally-generated bounces</i>
4054     <a href="postconf.5.html#header_checks">header_checks</a> = <i>don't reject internally-generated bounces</i>
4065     <a href="postconf.5.html#body_checks">body_checks</a> = <i>don't reject internally-generated bounces</i>
407</pre>
408</blockquote>
409
410<h3><a name="errors">Milter error handling</a></h3>
411
412<p> The <a href="postconf.5.html#milter_default_action">milter_default_action</a> parameter specifies how Postfix handles
413Milter application errors. The default action is to respond with a
414temporary error status, so that the client will try again later.
415Specify "accept" if you want to receive mail as if the filter does
416not exist, and "reject" to reject mail with a permanent status.
417The "quarantine" action is like "accept" but freezes the message
418in the "<a href="QSHAPE_README.html#hold_queue">hold" queue</a>, and is available with Postfix 2.6 or later.
419</p>
420
421<blockquote>
422<pre>
423/etc/postfix/<a href="postconf.5.html">main.cf</a>:
424    # What to do in case of errors? Specify accept, reject, tempfail,
425    # or quarantine (Postfix 2.6 or later).
426    <a href="postconf.5.html#milter_default_action">milter_default_action</a> = tempfail
427</pre>
428</blockquote>
429
430<p> See "<a href="#per-milter">Different settings for different
431Milter applications</a>" for advanced configuration options. </p>
432
433<h3><a name="version">Milter protocol version</a></h3>
434
435<p> As Postfix is not built with the Sendmail libmilter library,
436you may need to configure the Milter protocol version that Postfix
437should use.  The default version is 6 (before Postfix 2.6 the default
438version is 2). </p>
439
440<blockquote>
441<pre>
442/etc/postfix/<a href="postconf.5.html">main.cf</a>:
443    # Postfix &ge; 2.6
444    <a href="postconf.5.html#milter_protocol">milter_protocol</a> = 6
445    # 2.3 &le; Postfix &le; 2.5
446    <a href="postconf.5.html#milter_protocol">milter_protocol</a> = 2
447</pre>
448</blockquote>
449
450<p> If the Postfix <a href="postconf.5.html#milter_protocol">milter_protocol</a> setting specifies a too low
451version, the libmilter library will log an error message like this:
452</p>
453
454<blockquote>
455<pre>
456<i>application name</i>: st_optionneg[<i>xxxxx</i>]: 0x<i>yy</i> does not fulfill action requirements 0x<i>zz</i>
457</pre>
458</blockquote>
459
460<p> The remedy is to increase the Postfix <a href="postconf.5.html#milter_protocol">milter_protocol</a> version
461number.  See, however, the <a href="#limitations">limitations</a>
462section below for features that aren't supported by Postfix. </p>
463
464<p> With Postfix 2.7 and earlier, if the Postfix <a href="postconf.5.html#milter_protocol">milter_protocol</a>
465setting specifies a too high
466version, the libmilter library simply hangs up without logging a
467warning, and you see a Postfix warning message like one of the
468following: </p>
469
470<blockquote>
471<pre>
472warning: milter inet:<i>host</i>:<i>port</i>: can't read packet header: Unknown error : 0
473warning: milter inet:<i>host</i>:<i>port</i>: can't read packet header: Success
474warning: milter inet:<i>host</i>:<i>port</i>: can't read SMFIC_DATA reply packet header: No such file or directory
475</pre>
476</blockquote>
477
478<p> The remedy is to lower the Postfix <a href="postconf.5.html#milter_protocol">milter_protocol</a> version
479number. Postfix 2.8 and later will automatically turn off protocol
480features that the application's libmilter library does not expect.
481</p>
482
483<p> See "<a href="#per-milter">Different settings for different
484Milter applications</a>" for advanced configuration options. </p>
485
486<h3><a name="timeouts">Milter protocol timeouts</a></h3>
487
488<p> Postfix uses different time limits at different Milter protocol
489stages. The table shows the timeout settings and the corresponding
490protocol stages
491(EOH = end of headers; EOM = end of message).  </p>
492
493<blockquote>
494
495<table border="1">
496
497<tr> <th> Postfix parameter </th> <th> Time limit </th> <th> Milter
498protocol stage</th> </tr>
499
500<tr> <td> <a href="postconf.5.html#milter_connect_timeout">milter_connect_timeout</a> </td> <td> 30s </td> <td> CONNECT
501</td> </tr>
502
503<tr> <td> <a href="postconf.5.html#milter_command_timeout">milter_command_timeout</a> </td> <td> 30s </td> <td> HELO,
504MAIL, RCPT, DATA, UNKNOWN </td> </tr>
505
506<tr> <td> <a href="postconf.5.html#milter_content_timeout">milter_content_timeout</a> </td> <td> 300s </td> <td> HEADER,
507EOH, BODY, EOM </td> </tr>
508
509</table>
510
511</blockquote>
512
513<p> Beware: 30s may be too short for Milter applications that do
514lots of DNS lookups.  However, if you increase the above timeouts
515too much, remote SMTP clients may hang up and mail may be delivered
516multiple times. This is an inherent problem with before-queue
517filtering. </p>
518
519<p> See "<a href="#per-milter">Different settings for different
520Milter applications</a>" for advanced configuration options. </p>
521
522<h3><a name="per-milter">Different settings for different Milter
523applications </a></h3>
524
525<p> The previous sections list a number of Postfix <a href="postconf.5.html">main.cf</a> parameters
526that control time limits and other settings for all Postfix Milter
527clients. This is sufficient for simple configurations. With more
528complex configurations it becomes desirable to have different
529settings for different Milter clients. This is supported with Postfix
5303.0 and later. </p>
531
532<p> The following example shows a "non-critical" Milter client with
533a short connect timeout, and with "accept" as default action when
534the service is unvailable. </p>
535
536<blockquote>
537<pre>
5381 /etc/postfix/<a href="postconf.5.html">main.cf</a>:
5392     <a href="postconf.5.html#smtpd_milters">smtpd_milters</a> = { inet:host:port,
5403         connect_timeout=10s, default_action=accept }
541</pre>
542</blockquote>
543
544<p> Instead of a server endpoint, we now have a list enclosed in {}. </p>
545
546<ul>
547
548<li> <p> Line 2: The first item in the list is the server endpoint.
549This supports the exact same "inet" and "unix" syntax as described
550earlier. </p>
551
552<li> <p> Line 3: The remainder of the list contains per-Milter
553settings. These settings override global <a href="postconf.5.html">main.cf</a> parameters, and
554have the same name as those parameters, without the "milter_" prefix.
555The per-Milter settings that are supported as of Postfix 3.0 are
556command_timeout, connect_timeout, content_timeout, default_action,
557and protocol.  </p>
558
559</ul>
560
561<p> Inside the list, syntax is similar to what we already know from
562<a href="postconf.5.html">main.cf</a>: items separated by space or comma. There is one difference:
563<b>you must enclose a setting in parentheses, as in "{ name = value
564}", if you want to have space or comma within a value or around
565"="</b>.  </p>
566
567<h3><a name="macros">Sendmail macro emulation</a></h3>
568
569<p> Postfix emulates a limited number of Sendmail macros, as shown
570in the table. Some macro values depend on whether a recipient is
571rejected (rejected recipients are available on request by the Milter
572application). Different macros are available at different Milter
573protocol stages (EOH = end-of-header, EOM = end-of-message); their
574availability is not
575always the same as in Sendmail. See the <a
576href="#workarounds">workarounds</a> section below for solutions.
577</p>
578
579<blockquote>
580
581<table border="1">
582
583<tr> <th> Sendmail macro </th> <th> Milter protocol stage </th>
584<th> Description </th> </tr>
585
586<tr> <td> i </td> <td> DATA, EOH, EOM </td> <td> Queue ID, also
587Postfix queue file name </td> </tr>
588
589<tr> <td> j </td> <td> Always </td> <td> Value of <a href="postconf.5.html#myhostname">myhostname</a> </td>
590</tr>
591
592<tr> <td> _ </td> <td> Always </td> <td> The validated client name
593and address </td> </tr>
594
595<tr> <td> {auth_authen} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
596login name </td> </tr>
597
598<tr> <td> {auth_author} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
599sender </td> </tr>
600
601<tr> <td> {auth_type} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
602login method </td> </tr>
603
604<tr> <td> {client_addr} </td> <td> Always </td> <td> Client IP
605address </td> </tr>
606
607<tr> <td> {client_connections} </td> <td> CONNECT </td> <td>
608Connection concurrency for this client (zero if the client is
609excluded from all smtpd_client_* limits). </td> </tr>
610
611<tr> <td> {client_name} </td> <td> Always </td> <td> Client hostname
612<br> When address &rarr; name lookup or name &rarr; address
613verification fails: "unknown" </td> </tr>
614
615<tr> <td> {client_port} </td> <td> Always (Postfix &ge;2.5) </td>
616<td> Client TCP port </td> </tr>
617
618<tr> <td> {client_ptr} </td> <td> CONNECT, HELO, MAIL, DATA </td>
619<td> Client name from address &rarr; name lookup <br> When address
620&rarr; name lookup fails: "unknown" </td> </tr>
621
622<tr> <td> {cert_issuer} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td>
623TLS client certificate issuer </td> </tr>
624
625<tr> <td> {cert_subject} </td> <td> HELO, MAIL, DATA, EOH, EOM </td>
626<td> TLS client certificate subject </td> </tr>
627
628<tr> <td> {cipher_bits} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td>
629TLS session key size </td> </tr>
630
631<tr> <td> {cipher} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td> TLS
632cipher </td> </tr>
633
634<tr> <td> {daemon_name} </td> <td> Always </td> <td> value of
635<a href="postconf.5.html#milter_macro_daemon_name">milter_macro_daemon_name</a> </td> </tr>
636
637<tr> <td> {mail_addr} </td> <td> MAIL </td> <td> Sender address
638</td> </tr>
639
640<tr> <td> {mail_host} </td> <td> MAIL (Postfix &ge; 2.6, only with
641<a href="postconf.5.html#smtpd_milters">smtpd_milters</a>) </td> <td> Sender next-hop destination </td> </tr>
642
643<tr> <td> {mail_mailer} </td> <td> MAIL (Postfix &ge; 2.6, only with
644<a href="postconf.5.html#smtpd_milters">smtpd_milters</a>) </td> <td> Sender mail delivery transport </td> </tr>
645
646<tr> <td> {rcpt_addr} </td> <td> RCPT </td> <td> Recipient address
647<br> With rejected recipient: descriptive text </td> </tr>
648
649<tr> <td> {rcpt_host} </td> <td> RCPT (Postfix &ge; 2.6, only with
650<a href="postconf.5.html#smtpd_milters">smtpd_milters</a>) </td> <td> Recipient next-hop destination <br> With
651rejected recipient: enhanced status code </td> </tr>
652
653<tr> <td> {rcpt_mailer} </td> <td> RCPT (Postfix &ge; 2.6, only with
654<a href="postconf.5.html#smtpd_milters">smtpd_milters</a>) </td> <td> Recipient mail delivery transport <br>
655With rejected recipient: "error" </td> </tr>
656
657<tr> <td> {tls_version} </td> <td> HELO, MAIL, DATA, EOH, EOM </td>
658<td> TLS protocol version </td> </tr>
659
660<tr> <td> v </td> <td> Always </td> <td> value of <a href="postconf.5.html#milter_macro_v">milter_macro_v</a>
661</td> </tr>
662
663</table>
664
665</blockquote>
666
667<h3><a name="send-macros">What macros will Postfix send to Milters?</a></h3>
668
669<p> Postfix sends specific sets of macros at different Milter protocol
670stages.  The sets are configured with the parameters as shown in the
671table below (EOH = end of headers; EOM = end of message). The
672protocol version is a number that Postfix sends at the beginning
673of the Milter protocol handshake. </p>
674
675<p> As of Sendmail 8.14.0, Milter applications can specify what
676macros they want to receive at different Milter protocol stages.
677An application-specified list takes precedence over a Postfix-specified
678list. </p>
679
680<blockquote>
681
682<table border="1">
683
684<tr> <th> Postfix parameter </th> <th> Milter protocol version </th>
685<th> Milter protocol stage </th> </tr>
686
687<tr> <td> <a href="postconf.5.html#milter_connect_macros">milter_connect_macros</a> </td> <td> 2 or higher </td> <td>
688CONNECT </td> </tr>
689
690<tr> <td> <a href="postconf.5.html#milter_helo_macros">milter_helo_macros</a> </td> <td> 2 or higher </td> <td>
691HELO/EHLO </td> </tr>
692
693<tr> <td> <a href="postconf.5.html#milter_mail_macros">milter_mail_macros</a> </td> <td> 2 or higher </td> <td> MAIL
694FROM </td> </tr>
695
696<tr> <td> <a href="postconf.5.html#milter_rcpt_macros">milter_rcpt_macros</a> </td> <td> 2 or higher </td> <td> RCPT
697TO </td> </tr>
698
699<tr> <td> <a href="postconf.5.html#milter_data_macros">milter_data_macros</a> </td> <td> 4 or higher </td> <td> DATA
700</td> </tr>
701
702<tr> <td> <a href="postconf.5.html#milter_end_of_header_macros">milter_end_of_header_macros</a> </td> <td> 6 or higher </td>
703<td> EOH </td> </tr>
704
705<tr> <td> <a href="postconf.5.html#milter_end_of_data_macros">milter_end_of_data_macros</a> </td> <td> 2 or higher </td>
706<td> EOM </td> </tr>
707
708<tr> <td> <a href="postconf.5.html#milter_unknown_command_macros">milter_unknown_command_macros</a> </td> <td> 3 or higher </td>
709<td> unknown command </td> </tr>
710
711</table>
712
713</blockquote>
714
715<p> By default, Postfix will send only macros whose values have been
716updated with information from <a href="postconf.5.html">main.cf</a> or <a href="master.5.html">master.cf</a>, from an SMTP session
717(for example; SASL login, or TLS certificates) or from a Mail delivery
718transaction (for example; queue ID, sender, or recipient). </p>
719
720<p> To force a macro to be sent even when its value has not been updated,
721you may specify macro default values with the <a href="postconf.5.html#milter_macro_defaults">milter_macro_defaults</a>
722parameter. Specify zero or more <i>name=value</i> pairs separated by
723comma or whitespace; you may even specify macro names that Postfix does
724know about! </p>
725
726<h2><a name="workarounds">Workarounds</a></h2>
727
728<ul>
729
730<li> <p> To avoid breaking DKIM etc. signatures with an SMTP-based
731content filter, update the before-filter SMTP client in <a href="master.5.html">master.cf</a>,
732and add a line with "-o <a href="postconf.5.html#disable_mime_output_conversion">disable_mime_output_conversion</a>=yes" (note:
733no spaces around the "="). For details, see the <a
734href="FILTER_README.html#advanced_filter">advanced content filter</a>
735example. </p>
736
737<pre>
738/etc/postfix/<a href="master.5.html">master.cf</a>:
739    # =============================================================
740    # service type  private unpriv  chroot  wakeup  maxproc command
741    #               (yes)   (yes)   (yes)   (never) (100)
742    # =============================================================
743    scan      unix  -       -       n       -       10      smtp
744        -o <a href="postconf.5.html#smtp_send_xforward_command">smtp_send_xforward_command</a>=yes
745        -o <a href="postconf.5.html#disable_mime_output_conversion">disable_mime_output_conversion</a>=yes
746        -o <a href="postconf.5.html#smtp_generic_maps">smtp_generic_maps</a>=
747</pre>
748
749<li> <p> Some Milter applications use the "<tt>{if_addr}</tt>" macro
750to recognize local mail; this macro does not exist in Postfix.
751Workaround: use the "<tt>{client_addr}</tt>" macro instead. </p>
752
753<li> <p> Some Milter applications log a warning that looks like
754this: </p>
755
756<blockquote> <pre>
757sid-filter[36540]: WARNING: sendmail symbol 'i' not available
758</pre>
759</blockquote>
760
761<p> And they may insert an ugly message header with "unknown-msgid"
762like this: </p>
763
764<blockquote>
765<pre>
766X-SenderID: Sendmail Sender-ID Filter vx.y.z host.example.com &lt;unknown-msgid&gt;
767</pre>
768</blockquote>
769
770<p> The problem is that Milter applications expect that the queue
771ID is known <i>before</i> the MTA accepts the MAIL FROM (sender)
772command.  Postfix does not choose a queue ID, which is used as the
773queue file name, until <i>after</i> it accepts the first valid RCPT
774TO (recipient) command. </p>
775
776<p> If you experience the ugly header problem, see if a recent
777version of the Milter application fixes it. For example, current
778versions of dkim-filter and dk-filter already have code that looks
779up the Postfix queue ID at a later protocol stage, and sid-filter
780version 1.0.0 no longer includes the queue ID in the message header.
781</p>
782
783<p> To fix the ugly message header, you will need to add code that
784looks up the Postfix queue ID at some later point in time. The
785example below adds the lookup after the end-of-message.  </p>
786
787<ul>
788
789<li> <p> Edit the filter source file (typically named
790<tt>xxx-filter/xxx-filter.c</tt> or similar). </p>
791
792<li> <p> Look up the <tt>mlfi_eom()</tt> function and add code near
793the top shown as <b>bold</b> text below: </p>
794
795</ul>
796
797<blockquote>
798<pre>
799dfc = cc->cctx_msg;
800assert(dfc != NULL);
801<b>
802/* Determine the job ID for logging. */
803if (dfc->mctx_jobid == 0 || strcmp(dfc->mctx_jobid, JOBIDUNKNOWN) == 0) {
804        char *jobid = smfi_getsymval(ctx, "i");
805        if (jobid != 0)
806                dfc->mctx_jobid = jobid;
807}</b>
808</pre>
809</blockquote>
810
811<p> NOTES: </p>
812
813<ul>
814
815<li> <p> Different mail filters use slightly different names for
816variables. If the above code does not compile, look elsewhere in
817the mail filter source file for code that looks up the "i" macro
818value, and copy that code.  </p>
819
820<li> <p> This change fixes only the ugly message header, but not
821the WARNING message.  Fortunately, many Milters log that message
822only once. </p>
823
824</ul>
825
826</ul>
827
828<h2><a name="limitations">Limitations</a></h2>
829
830<p> This section lists limitations of the Postfix Milter implementation.
831Some limitations will be removed as the implementation is extended
832over time. Of course the usual limitations of before-queue filtering
833will always apply. See the <a href="CONTENT_INSPECTION_README.html">CONTENT_INSPECTION_README</a> document for
834a discussion. </p>
835
836<ul>
837
838<li> <p> The Milter protocol has evolved over time. Therefore,
839different Postfix versions implement different feature sets. </p>
840
841<table border="1">
842
843<tr> <th> Postfix </th> <th> Supported Milter requests </th>
844</tr>
845
846<tr> <td align="center"> 2.6 </td> <td> All Milter requests of
847Sendmail 8.14.0 (see notes below).  </td> </tr>
848
849<tr> <td align="center"> 2.5 </td> <td> All Milter requests of
850Sendmail 8.14.0, except: <br> SMFIP_RCPT_REJ (report rejected
851recipients to the mail filter), <br> SMFIR_CHGFROM (replace sender,
852with optional ESMTP parameters), <br> SMFIR_ADDRCPT_PAR (add
853recipient, with optional ESMTP parameters). </td> </tr>
854
855<tr> <td align="center"> 2.4 </td> <td> All Milter requests of
856Sendmail 8.13.0.  </td> </tr>
857
858<tr> <td align="center"> 2.3 </td> <td> All Milter requests of
859Sendmail 8.13.0, except: <br> SMFIR_REPLBODY (replace message body).
860
861</table>
862
863<li> <p> For Milter applications that are written in C, you need
864to use the Sendmail libmilter library. </p>
865
866<li> <p> Postfix has TWO sets of mail filters: filters that are used
867for SMTP mail only (specified with the <a href="postconf.5.html#smtpd_milters">smtpd_milters</a> parameter),
868and filters for non-SMTP mail (specified with the <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a>
869parameter).  The non-SMTP filters are primarily for local submissions.
870</p>
871
872<p> When mail is filtered by <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a>, the Postfix <a href="cleanup.8.html">cleanup(8)</a>
873server has to simulate SMTP client requests.  This works as expected,
874with only one exception: <a href="postconf.5.html#non_smtpd_milters">non_smtpd_milters</a> must not REJECT or
875TEMPFAIL simulated RCPT TO commands. When this rule is violated,
876Postfix will report a configuration error, and mail will stay in
877the queue.  </p>
878
879<li> <p> When you use the before-queue content filter for incoming
880SMTP mail (see <a href="SMTPD_PROXY_README.html">SMTPD_PROXY_README</a>), Milter applications have access
881only to the SMTP command information; they have no access to the
882message header or body, and cannot make modifications to the message
883or to the envelope. </p>
884
885<li> <p> Postfix 2.6 ignores the optional ESMTP parameters in
886requests to replace the sender (SMFIR_CHGFROM) or to append a
887recipient (SMFIR_ADDRCPT_PAR). Postfix logs a warning message when
888a Milter application supplies such ESMTP parameters: </p>
889
890<pre>
891warning: <i>queue-id</i>: cleanup_chg_from: ignoring ESMTP arguments "<i>whatever</i>"
892warning: <i>queue-id</i>: cleanup_add_rcpt: ignoring ESMTP arguments "<i>whatever</i>"
893</pre>
894
895<li> <p> Postfix 2.3 does not implement requests to replace the
896message body. Milter applications log a warning message when they
897need this unsupported operation: </p>
898
899<pre>
900st_optionneg[134563840]: 0x3d does not fulfill action requirements 0x1e
901</pre>
902
903<p> The solution is to use Postfix version 2.4 or later. </p>
904
905<li> <p> Most Milter configuration options are global. Future Postfix
906versions may support per-Milter timeouts, per-Milter error handling,
907etc. </p>
908
909</ul>
910
911</body>
912
913</html>
914