I followed postfix documentation to set up a script that I can use to write custom filters on incoming mail on the check_policy_service event and it works just fine, but I cannot access the email body - only the following parameters from STDIN:

Array
(
    [request] => smtpd_access_policy
    [protocol_state] => RCPT
    [protocol_name] => ESMTP
    [client_address] => 208.40.44.179
    [client_name] => smtprelay0179.hostedemail.com
    [client_port] => 59713
    [reverse_client_name] => smtprelay0179.hostedemail.com
    [helo_name] => smtprelay.hostedemail.com
    [sender] => john@doe.net
    [recipient] => mary@doe.com
    [recipient_count] => 0
    [queue_id] => 
    [instance] => 27c5.5bccec9c.5f5b9.0
    [size] => 1905
    [etrn_domain] => 
    [stress] => 
    [sasl_method] => 
    [sasl_username] => 
    [sasl_sender] => 
    [ccert_subject] => 
    [ccert_issuer] => 
    [ccert_fingerprint] => 
    [ccert_pubkey_fingerprint] => 
    [encryption_protocol] => TLSv1.2
    [encryption_cipher] => AECDH-AES256-SHA
    [encryption_keysize] => 256
    [policy_context] => 
)

How can I access the raw email (headers and body) so that my filtering can optionally depend on that as well?

In master.cf I have configured my script like this:

filtermyemail unix - n n - 0 spawn
  user=someuser argv=php /path-to-scripts/filter-incoming-email.php

Access policy delegation doesn't transmit the message body. You'll need to create a milter instead, if you need access to the message body.

  • I see... not straightforward though... It doesn't say how you can write your own filter. Currently I use check_policy_service unix:private/filtermyemail in main.cf to specify my own filter but would I do the same with smtpd_milters? And what output should the filter have? Documentation doesn't say anything about that... – TheStoryCoder Oct 22 at 15:31
  • @TheStoryCoder It didn't take me long to find a description of the milter protocol, though it wasn't the first result in a Google search.... As for configuring Postfix, you would just add your new milter's connection information to smtpd_milters. But before you go any farther, you should probably search some more and determine whether an existing program can do the filtering you require (e.g. MIMEDefang). And consider using another language which already has a milter library available (e.g. perl, Python, Java)... – Michael Hampton Oct 22 at 15:38
  • I see writing your own milter is not an easy thing...! I guess I'll have a look at MIMEDefang... – TheStoryCoder Oct 23 at 0:55

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.