Find the answer to your Linux question:
Results 1 to 4 of 4

Thread: Postfix Filter

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Postfix Filter


    I am new to linux and postfix. I would really appreciate any help. I wrote a python script to extract mime-attachments from email received at the postfix server but only for the local user i.e. for the ones saved in the folder /var/mail/$USER. But now I want to run the same script before the mails are dropped into the respective mailboxes, so I can do the same for all the recipients. For this I looked at the following link:

    Postfix After-Queue Content Filter
    and made the specified changes in the file for the Simple Content Filter.

    My python script:

    #!/usr/bin/env python

    import sys, os, string, mimetools, multifile, email, errno, mimetypes
    import mailbox
    import pdb
    import MySQLdb
    from optparse import OptionParser
    from email.Utils import parsedate
    import random
    import md5

    directory = "/home/scofmon/Desktop/Spam Analysis Stuff/Extracted Mail"

    def extract(msg):
    for part in e_msg.walk():
    conn = MySQLdb.connect(db="spamattachments",host="localho st",user="",passwd="");
    #done something here

    print "Disconnected<br/>"

    def main():
    msgfile = "/var/mail/scofmon"
    fp = open(msgfile, 'r')
    mb = mailbox.UnixMailbox(fp, email.message_from_file)
    msg =
    while msg is not None:
    #document =
    msg =
    print "fp disconnected"

    if __name__ == "__main__":

    changes in

    smtp inet n - - - - smtpd
    -o content_filter=filter:dummy

    filter unix - n n - 10 pipe
    flags=Rq user=scofmon argv=/home/scofmon/Desktop/spam-analysis-stuff/

    This script works fine. But, as I said i need to change my python script to work NOT on mails in /var/mail/scofmon but rather at the server queue itself before the mails are dropped into the mailbox. I able not able to understand how this filter thing works.

    1. Now that I have made changes to, are the files directly sent to my script?
    2. How can my script access these mails? through command line argumengts. through some pre-defined variable?
    3. if my script is not running all the time, where would the mails go?
    4. The file sent to the script is a single mail file as was in the case of /var/mail/scofmon or its multiple files?

    I might have asked some really stupid or confusing questions, but I am totally confused right now and hope someone could help me out.

    Thnx a lot in advance.

  2. #2
    i think it might be much easier if you use mail filtering tools like amavisd-new or others. These kind of tools can be set up where postfix will pass the mail to them for scanning and pass back to postfix. It is very flexiable, and from what you describing what you want to do, i think this would be easily set up.


  3. #3

    Smile Thanx a lot :)


    I am new to amavisd-new. I'll install it and hopefully shud be able to make things work properly. Thnx a lot for your kind help . I really appreciate it.


  4. $spacer_open
  5. #4
    Hi all,

    I installed amavisd-new version 2.5.3-1. And as I mentioned above, I want to send all the mails (globally) to amavisd and from there call my external python script to perform some function on each mail.

    I have 2 ques:
    1. I wanted to configure amavisd so that all mails go to amavisd. I referred to the following link: (since I am using postfix as the MTA).

    The link talks about the config file amavisd.conf. However with the package that I got from the repos, there is no single conf file. However various files such as 50-user, 15-content_filter_mode, 20-debian_defaults, etc.

    So I dont get, in which file I need to make the specified changes. (I am using ubuntu hardy heron).

    2. Is it possible to call an external script from amavisd and run it on each mail received by the amavisd. If yes, how? Is there some online resource for that?

    Thank you in advance for the help.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts