At 17:40 3-7-2002, Martin Jermyn wrote:
What I would like to do is setup a procmail rule or something along those
lines that enters email into a mySQL database
I use php in combination with procmail for this like (I use it only to
monitor the first 100 lines of bounced mail)
IN PROCMAIL:
--------------------
:0
* ^FROM_MAILER
{
CPXFROM=`formail -rt -xTo:`
CPXEMAILID=`formail -xMessage-ID:`
CPXSUBJECT=`formail -xSubject:`
# Pipe body (b) of message to returnedmail.php with the current CP-Guid
# ignore (i) early stopped reading (only first x lines will be taken)
:0 bi
| php -q $USERDIR/returnedmail.php >> $USERDIR/returnedmail.log
}
IN PHP:
-----------
## Read first 100 lines of email from stdin
$ fp = fopen ( "/dev/stdin", "r");
$content = ""; $i=0;
while ((!feof ($fp)) && ($i < 100))
{
$content .= fgets($fp, 256);
$i++;
}
fclose ($fp);
## Connect to database
$g_link = mysql_connect('localhost', 'user', 'password');
if (mysql_select_db("databasename", $g_link)) {
$query = "INSERT INTO emails VALUES ('",$CPXFROM,"',
'",$CPXEMAILID,"', '",$CPXSUBJECT,"', '" $content."', stamp=NOW()";
mysql_query($query);
}
I just picked some bits and pieces, so you need to complete it off course....
cheers,
Peter Fekkes.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail