将所有新电子邮件传输到数据库 [英] Transfer all new e-mails to a database
问题描述
我正在为Linux邮件服务器使用后缀。目的是将所有包含标题和消息信息的传入邮件转储到数据库中,然后从邮件服务器中删除该电子邮件。有什么方法可以使postfix每次收到新电子邮件时都将消息发布到php文件中,然后删除该电子邮件?我可以看到的另一种方法是制作一个脚本来轮询电子邮件服务器,读取每个邮件并将内容传输到数据库,然后从邮件服务器中删除邮件。能够让postfix自动为所有新收到的邮件执行php脚本是一个更好的选择。如果有所不同,则邮件服务器和带有php文件的服务器是相同的。
I am using postfix for my linux mail server. The goal is to have any incoming mail dumped into a database with the headers and message information, then the e-mail being deleted from the mail server. Is there any way to make postfix post a message to a php file everytime a new e-mail comes in then delete the e-mail message? The only other way I can see to make a script to poll the e-mail server, read each mail and transfer the contents to a database, then delete the messages from the mail server. Being able to have postfix automatically execute the php script for all new incoming mails would be a better choice. If it makes a difference, the mail server and the server with the php file is the same. Any direction in this matter would be greatly appreciated.
推荐答案
使用.forward,/ etc / aliases,hashtable等将邮件转发至
use .forward, /etc/aliases, hashtable etc to forward mail to a script.
在/ etc / aliases中,我有
In /etc/aliases, I have
mysite-confirm: |/home/mysite/confirm.sh
在confirm.sh中,我有
In confirm.sh, I have
#!/bin/sh
basedir=/home/mysite/www
php -d include_path=$basedir/includes -f $basedir/cli/confirm.php
在confirm.php中,魔术发生:
In confirm.php, the magic happens:
$contents = file_get_contents("php://stdin");
do_magic_with_mail($contents);
所有操作都非常简单和严格。唯一的缺点是您可以邮寄mysite-confirm@any_domain_I_host.com,但可以使用正确的别名/ virtualmaps等修复该问题。
All quite simple and rigid. The only downside is that you could mail mysite-confirm@any_domain_I_host.com, but you can fix that with the right aliases / virtualmaps etc.
这篇关于将所有新电子邮件传输到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!