naif
naif

Reputation: 1

Transfer all new e-mails to a database

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.

Upvotes: 0

Views: 216

Answers (1)

mvds
mvds

Reputation: 47104

use .forward, /etc/aliases, hashtable etc to forward mail to a script.

In /etc/aliases, I have

mysite-confirm: |/home/mysite/confirm.sh

In confirm.sh, I have

#!/bin/sh
basedir=/home/mysite/www
php -d include_path=$basedir/includes -f $basedir/cli/confirm.php

In confirm.php, the magic happens:

$contents = file_get_contents("php://stdin");
do_magic_with_mail($contents);

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.

Upvotes: 2

Related Questions