如何设置后缀来将电子邮件存储在文件中而不是中继?

我想在本地环境中运行生产服务器的临时副本。 系统运行一个PHP应用程序,该应用程序在各种情况下向客户发送电子邮件,并且要确保从暂存环境中没有发送电子邮件。

我可以调整代码,以便使用虚拟电子邮件发件人,但是我想运行与生产环境完全相同的代码。 我可以使用不同的MTA(Postfix就是我们在生产中使用的),但我想要在Debian / Ubuntu下设置一些简单的东西:)

所以,我想设置本地Postfix安装来存储(一个或多个)文件中的所有电子邮件,而不是中继它。 实际上,只要检查发送的电子邮件是可行的,我并不关心它是如何存储的。 即使是一个设置选项,告诉后缀保持在邮件队列中的电子邮件将工作(我可以清除队列,当我重新加载生产副本的登台服务器)。

我知道这是可能的,我只是没有find任何好的解决scheme,似乎是一个相当普遍的需要。

谢谢!

    我使用pipe道命令创build了一个新的传输,将电子邮件写入文件。

    基本上:

    1. 创build一个拥有电子邮件的用户(或使用现有的用户)。 我给我打电话
    2. mkdir /home/email/bin
    3. 将以下脚本放在/home/email/bin/mail_eater (使用PHP,但可以使用任何您喜欢的语言编写自己的版本,只需将stdin附加到文件中):

       #!/usr/bin/php <?php $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); $fh = fopen('/home/email/email.txt','a'); fwrite($fh, $email."\n-------------------------------------------------------\n\n"); fclose($fh); 
    4. chmod a+x /home/email/bin/mail_eater
    5. touch /home/email/email.txt
    6. chmod a+r /home/email/email.txt
    7. 通过在master.cf追加以下行来创build使用此文件的新传输:

       file_route unix - nn - - pipe user=email argv=/home/email/bin/mail_eater 
    8. 将其用作main.cf的默认传输:

       default_transport = file_route 

    那里 :)

    你可以把这些域放在main.cf $mydestination中,所以postfix将在本地传递它。

    如果您愿意,可以设置不同的本地用户,也可以设置本地收件人地址以将电子邮件只发送到一个帐户,更多详细信息在这里: http : //www.postfix.org/ADDRESS_REWRITING_README.html#luser_relay

    对于所有领域:

     mydestination = pcre:/etc/postfix/mydestinations 

    /etc/postfix/mydestinations应该包含

     /.*/ ACCEPT 

    我现在不能testing,但它应该工作。

    尝试(在main.cf中):

     defer_transports = smtp 

    你可以看到队列postqueue -p并用postcat看内容

    根据你的分布,你可以看看“nullmailer”。 这是一个中继MTA,它会继续到您的networking或远程的另一个SMTP。 这很可能是一个无效的SMTP,在这种情况下,它可能只会把它放到机器上的文件夹的队列中。

    在Debian和Ubuntu上,这个可以作为你的系统的替代MTA。

    这是从我的博客http://blog.malowa.de/2011/04/postfix-as-spam-trap-server.html复制和稍加修改&#xFF1A;

    你甚至不需要configurationPostfix作为一个nullmailer。 Postfix附带了一个叫做smtp-sink的简洁工具, smtp-sink主要是作为SMTP客户端需要服务器玩的testing工具。 因此,您可以configuration它以logging整个对话,甚至将每个收到的邮件转储到一个文件。 后者是一个nullmailer需要的。

    没有configuration文件来configurationsmtp-sink。 一切都是通过命令行选项完成的。

     smtp-sink -c -d "%Y%m%d%H/%M." -f . -u postfix -R /tmp/ -B "550 5.3.0 The recipient does not like your mail. Don't try again." -h spamtrap.example.com 25 1024 

    让我们仔细看看每个参数。

     -u postfix Runs the program under the user "postfix" -R /tmp/ Sets the output directory to /tmp/. In this directory the mails will be stored. If you have a high spam volume (hundreds of Spam per minute) it is recommended to write the mails to a ramdisk -d "%Y%m%d%H/%M." Writes the mail to a directory of the format "YearMonthDayHour" and in this directory the files are name "Month.RandomID". Note that the dates are in UTC -c Write statistics about connection counts and message counts to stdout while running -f . Reject the mail after END-OF-DATA. But the mail will be saved. Cool, isn't it?! -B "550 5.3.0 The recipient does not like your mail. Don't try again" This is the rejection message after END-OF-DATA. -h spamtrap.example.com Announce the hostname spamtrap.example.com 25 The port to listen on. Can be prepended with an IP or host if you want to bind on a special interface. 1024 The backlog count of connections that can wait in the TCP/IP stack before they get a free slot for sending mail. 

    您可以在smtp-sink的手册页中find更多信息,但这些是运行全面垃圾收集器的重要信息。 在这个configuration中,程序接受任何大小的邮件,从任何发件人到IPv4和IPv6的任何收件人。 唯一的限制是,与1024个排队连接只有256个同时连接,并且程序被标记为实验性的。 所以不要在生产环境中使用smtp-sink。

    -B选项仅在较新版本的Postfix中有效。 在2.7.1中,它不见了。 在2.8.2它是存在的。 介于它之间的某个地方。