CREATE TABLE IF NOT EXISTS journal_smtp (
    id            SERIAL PRIMARY KEY,
    created_at    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
    script_path   VARCHAR(512),
    to_email      VARCHAR(255) NOT NULL,
    subject       VARCHAR(512),
    content_html  TEXT,
    content_text  TEXT,
    status        VARCHAR(20) NOT NULL DEFAULT 'queued',
    ip            VARCHAR(128),
    user_agent    VARCHAR(512),
    error_message VARCHAR(1000),
    sent_at       TIMESTAMP WITH TIME ZONE
);
CREATE INDEX IF NOT EXISTS idx_journal_smtp_created_at ON journal_smtp (created_at DESC);
CREATE INDEX IF NOT EXISTS idx_journal_smtp_to_email   ON journal_smtp (to_email);
