Logging Outgoing Mail from Postfix with Node.js and TeqFW DI

Date: 2025-04-13

Logging Outgoing Mail from Postfix with Node.js and TeqFW DI

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

💡 Note: Database schema is not created automatically. Run init-db manually before logging.

Why you might need it

Setup is straightforward and covered in the README. I hope it’s useful for anyone building infrastructure with Node.js and Postfix.