Logging Outgoing Mail from Postfix with Node.js and TeqFW DI
While developing NutriLog, I needed to track all outgoing emails sent through Postfix. This led to the creation of a small tool — smtp-logger.
This is a simple Node.js utility that connects to Postfix as a pipe handler. It
receives the complete email via stdin, extracts the sender, recipient, and subject, and saves the entire "raw"
MIME structure to a SQL database (PostgreSQL, SQLite, MySQL, etc. via knex).
What makes this project interesting?
It's a working example of using ES6 modules and late dependency binding in JS architecture. The entire structure is built using @teqfw/di — a lightweight DI container compatible with native JavaScript (no TypeScript or bundlers required).
Features
Integration with Postfix via
pipe(e.g., throughalways_bcc)Extraction of
from,to, andsubject+ saving the entire emailWorks with any database supported by
knexCLI interface:
init-dbandlogcommandsSQLite support for local logging
Important: the database schema is not created automatically. Before use, you must manually
run the init-db command.
If you use Postfix only for outgoing mail — this is an excellent solution for auditing, debugging, and logging messages in production or staging environments.