[exim] Special logging for successful deliveries

Top Page
Delete this message
Reply to this message
Author: Chris Lear
Date:  
To: exim-users
Subject: [exim] Special logging for successful deliveries
I was asked some time ago to set up special logging for certain
deliveries. The e-mails are generated by a web application, and the
developers wanted to correlate their application logs with logs of
e-mails actually leaving the building, as it were.

The e-mails in question have a recognisable x- header.

What I came up with was a router like this:

special_router:
driver = redirect
allow_filter
user = mail
group = mail
file = /etc/exim/special_filter

The filter file looks like this:

#Exim filter
if $h_x_application_flash:is not "" then
    logfile /var/log/exim/special_log/log 640
    logwrite $message_headers
endif


This writes the message headers into the special log file, then the
message is delivered as usual. What they do with the log file is their
problem.

Here's the difficulty. Because this logging is done at routing time, an
entry in the log doesn't actually mean that the mail has been delivered.
Mail that gets queued and retried, for example, gets logged multiple
times, but may never reach the recipient.

I suppose the ideal thing for the situation would be something like this:

Whenever exim is about to write a => log line for a message (multiple
recipients aren't really an issue, but it could be done for -> lines as
well), check for an x_application_flash header. If the header exists,
then write the full headers to a special log file.

What I've come up with so far is just to check that there is no
corresponding entry in /var/spool/exim/msglog before treating the
delivery as completed. But that's not amazingly satisfying.

I expect I'm missing something basic, hence the query. Can you tell me
how to do this?

Thanks,

Chris