---
title: "Logging Outgoing Mail from Postfix with Node.js and TeqFW DI"
description: "Created a utility for logging outgoing Postfix emails to SQL via Node.js and @teqfw/di."
date: 2025-04-13
display_date: "April 13, 2025"
image: "/img/brand/teqfw.webp"
image_alt: "smtp-logger for Postfix and Node.js"
---

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

<zoom-img
            src="/img/brand/teqfw.webp"
            alt="TeqFW smtp-logger"
            width="100px"
            style="float: left; margin: 15px 15px 0 0;"
    ></zoom-img>

While developing NutriLog, I needed to track all outgoing emails sent through **Postfix**.
        This led to the creation of a small tool —
        [smtp-logger](https://github.com/flancer64/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](https://github.com/teqfw/di) — a lightweight
        DI container compatible with native JavaScript (no TypeScript or bundlers required).

#### Features

- Integration with Postfix via `pipe` (e.g., through `always_bcc`)

- Extraction of `from`, `to`, and `subject` + saving the entire email

- Works with any database supported by `knex`

- CLI interface: `init-db` and `log` commands

- SQLite 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.
