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