-1

I am using postfix and already usHi. I am using postfix and already using a script as a content_filter which re-injects back to smtpd to all users, but before this happens, I would like to make a copy of the email as well. Do I need multiple content_filters? This does not need to get re-injected back to smtpd since I am just looking to make a copy of the email so I don't think I need to pass this off into my other script. It should be separate. An email should be copied to a local dest as well as go through the script which goes out through smtpd to deliver the email to the recipient. So this is all for just outgoing emails. I am pretty sure it has something to do with using the pipe and to a file but would like guidance on proper syntax and if I should be using a script, two content_filters, and how those two can be configured to work concurrently. I also don't think I can use the always_bcc option here since it would just make a copy of the email AFTER it goes through the current content_filter, unless I am wrong about that. Thanks for any help.

  • Yeah, you're right about the `always_bcc`. If you're looking to write a pipe script to copy the email, it should be fairly straight forward.. though you do need to decide how you store your copy. – NickW Feb 23 '14 at 09:54

1 Answers1

1

Yes I was thinking about that. I was thinking the script below could catch the email from STDIN and feed it to a file but this file would need to be unique so I was thinking something along the lines of using the date command up until the milliseconds just in case more than 1 person sends an email at the same time. The file must be unique. Also the proper syntax in master.cf would be appreciated but this is what I think could work:

#!/usr/bin/php
<?php
$file = fopen("/tmp/postfixtest", "a");
fwrite($file, "Script successfully ran at ".date("Y-m-d H:i:s")."\n");


// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $line = fread($fd, 1024);
    $email .= $line;
}
fclose($fd);

fwrite($file, $email);
fclose($file);

?>
pipetosed
  • 19
  • 4
  • If you want to make a copy before anything else, I'd read through this: http://www.postfix.org/SMTPD_PROXY_README.html and this: http://www.postfix.org/FILTER_README.html the second allows pipe methods, but may not run before your content_filter. – NickW Feb 23 '14 at 15:49