Logging Outgoing Mail from Postfix with Node.js and TeqFW DI
Date: 2025-04-13

While working on NutriLog, I needed a way to log all outgoing emails sent by Postfix. Since my setup only uses Postfix for outbound traffic (no inboxes), I had no visibility into what was being sent. So I built a minimal open-source tool:
📬 smtp-logger
It’s a small Node.js utility that works as a pipe handler for Postfix. It receives full email messages via stdin
, extracts only the sender, recipient, and subject, and stores the entire raw message in a SQL database (PostgreSQL, SQLite, MySQL — any knex
-compatible backend). The raw content remains untouched for later inspection.
What makes it interesting?
This project is a practical demonstration of using ES6 modules and late binding in JavaScript, showing how a clean modular architecture can be applied to a real-world problem.
The code is powered by @teqfw/di
— my lightweight dependency injection container designed for modern JS without transpilation or TypeScript. It’s inspired by traditional enterprise frameworks, but adapted to ES modules and file-based imports.
Features
- Works as a
pipe
-based Postfix handler (e.g. viaalways_bcc
) - Extracts
from
,to
, andsubject
for indexing, saves full MIME message - Uses
knex
for DB abstraction - CLI interface with
log
andinit-db
commands - Works with both local (SQLite) and remote (PostgreSQL, etc.) databases
💡 Note: Database schema is not created automatically. Run
init-db
manually before logging.
Why you might need it
- Track all outgoing system-generated emails
- Add audit trails in staging or production
- Debug or monitor apps sending mail through Postfix
Setup is straightforward and covered in the README. I hope it’s useful for anyone building infrastructure with Node.js and Postfix.