Discussion:
How to log X-Header data from undeliverable message???
(too old to reply)
Zbigniew Szczęsny
2021-01-26 01:10:10 UTC
Permalink
Hi,

I try to integrate Postix with an external sales application.

PHP sales application is delivering voucher information via e-mail. It registers related customer-id and order-id information in specific e-mail X-Headers.

I would love to have these data in Postfix log. I was able to rely Postfix log to Rsyslog and pass it via UDP to a simple UDP server where it is organized using queue ids as keys.

Using header_check I was able to successfully collect such a collection for a deliverable message:

Array
(
[queue_id] => 6FDC5900000006187D
[from] => ***@my-server.org
[log_start_time] => 2021-01-26 01:55:28
[message_id] => ***@my-server.org
[log_updt_time] => 2021-01-26 01:55:29
[pid] => 123456
[oid] => 7654321
[mt] => 1
[to] => ***@other-server.org
[status] => sent
[comment] => 250 OK id=1l4Cdk-0000tg-4f
)

You may notice: pid, oid and mt are "person_id", "offer_id" and "message type" scrapped from relating X-Header data.

But for undeliverable e-mail header checks are skipped by the Postfix cleanup server - for better "performance" - so I cannot track undelivered e-mails in my sales application :-/

Any idea how to log queue_id and X-Header data for outgoing messages also in case of undeliverable e-mails???

Please notice - I do not want to filter messages actually. I want to know what has happened with given message sent by the sales application. I need "delivery tracking system" for e-mails.

Workable ideas will be appreciated - thanks ahead!
Zbigniew Szczęsny
2021-01-26 03:50:25 UTC
Permalink
I have found some workaround...

So, if I get deferred status then I execute shell script in PHP:

postcat -hq $1

where $1 argument is queue_id.

Then I can extract necessary X-Headers from output. So finally I get:

Array
(
[queue_id] => 83ABA29000000176C18
[from] => ***@my-server.org
[log_start_time] => 2021-01-26 04:37:43
[message_id] => ***@my-server.org
[log_updt_time] => 2021-01-26 04:38:04
[to] => ***@other-server.org
[pid] => 123456
[poid] => 7654321
[mt] => 1
[status] => deferred
[comment] => connect to other-server.org[XXX.XXX.XXX.XXX]:25: Connection refused
)

This array can be send to database, and records then be matched against person_id, order_id etc.

Perhaps this is not the best solution, and not the most efficient, but it looks workable.
Loading...