K
K
Kirill Gorelov2015-10-13 15:41:34
PHP
Kirill Gorelov, 2015-10-13 15:41:34

How to parse mail server logs?

Hello.
There is a mail server.
It has logs for sending emails (I'm a cap).
The essence of the question: how to read these logs through a php script.
what would then from what the script reads build a simple table for clarity?
I know that there are bin scripts (which read them in the "terminal", but that's not it).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2015-10-13
@POS_troi

Open the file using
php ( file (); )

E
Eugene Tatarinov, 2015-10-13
@darkkemper

To successfully extract the necessary information from the log file, you just need to study it and write a regular expression to extract the necessary data. For example, this is how you can read the Exim mail server log file and select the email sender and recipient:

$logs = file('log');

foreach($logs as $num => $line)
{
    /**
     * Регулярное выражение нужно делать по своему примеру
     */
    preg_match('/F=<(.*?)>.*?RCPT\s<(.*?)>/', $line, $recipient);

    if (isset($recipient[1]) && isset($recipient[2]))
    {
        echo "Sender: " . $recipient[1] . " Recipient: " . $recipient[2] . "\n";
    }
}

From this log file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question