altermime + php

Discussion in 'Installation/Configuration' started by stef157, Dec 27, 2016.

  1. stef157

    stef157 Member

    Hi all,
    I'm trying to modify all the outgoing email.
    So I've manage to do something but it's not the right way (DKIM fail)

    In my master.cf :
    Code:
    127.0.0.1:10027 inet n - n - - smtpd
            -o content_filter=dfilt:
    dfilt     unix    -       n       n       -       -       pipe
        flags=Rq user=filter argv=/etc/postfix/disclaimer -f ${sender} -- ${recipient}
    
    and my disclaimer :
    Code:
    #!/bin/sh
    # Localize these.
    INSPECT_DIR=/var/spool/filter
    SENDMAIL=/usr/sbin/sendmail
    
    # Exit codes from <sysexits.h>
    EX_TEMPFAIL=75
    EX_UNAVAILABLE=69
    
    
    php -f /var/www/test-infos/ok.php in.$$ $@
    
    # Clean up when done or when aborting.
    trap "rm -f in.$$" 0 1 2 3 15
    
    # Start processing.
    cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit
    $EX_TEMPFAIL; }
    
    #cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
    
    
    
    #/usr/bin/altermime --input=in.12 \
    #                   --disclaimer=/etc/postfix/disclaimer.txt \
    #                   --disclaimer-html=/etc/postfix/disclaimer.txt \
    #                   --xheader="X-Copyrighted-Material: Please visit http://www.company.com/privacy.htm" || \
    #                     { echo Message content rejected; exit $EX_UNAVAILABLE; }
    
    
    $SENDMAIL -oi "$@" <in.$$
    
    exit $?
    
    After that I'm using PHP to modify mail email content like this :
    Tho goal of this is to track all outgoing email and to get some stats on the opening rate.

    Thanks for your help !
    PHP:
    try {
            
    $db = new PDO($dsn$user$password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
        } catch (
    PDOException $e) {
            echo 
    'Connexion échouée : ' $e->getMessage();
        }
      
        
    $file        =    fopen("/var/spool/filter/".$argv[1], "a");

        
    $from        =    $argv[3];
        
    $to            =    $argv[5];
      
        
    $insert        =    $db->prepare('insert into emails (emailfrom, emailto) values (:emailfrom, :emailto)');
        
    $insert->bindParam(':emailfrom',    $from,    PDO::PARAM_STR);
        
    $insert->bindParam(':emailto',        $to,    PDO::PARAM_STR);
        
    $insert->execute();
        
    $id            =    $db->lastInsertId();
      
        
    $input file_get_contents("php://stdin");
      
      
      
        
    $input str_replace(
            
    '</body>',
            
    '<img src="http://myURL.com/ok/open.php?id='.$id.'" height="1" width="1"/></body>',
            
    $input
        
    );
      
        
    fwrite($file$input);
      
        
    fclose($file);
     

Share This Page