SMTP Zen Logo
Skip to main content
Published Dec 10, 2025Updated Aug 12, 2026

Nodemailer one-click unsubscribe: RFC 8058 example

Add RFC 8058 List-Unsubscribe headers in Nodemailer and implement a secure HTTPS POST endpoint for Gmail and Yahoo.
deliverabilityrfc 8058nodemailergmailyahoo
Nodemailer one-click unsubscribe: RFC 8058 example

Nodemailer can add RFC 8058 headers to marketing and subscribed messages without a provider-specific API. Ordinary transactional messages such as password resets and receipts do not require one-click unsubscribe.

Quick primer: required headers

  • List-Unsubscribe: include an HTTPS endpoint; mailto can be an additional fallback.
  • List-Unsubscribe-Post: List-Unsubscribe=One-Click: signals that the provider should send an RFC 8058 POST.
  • Process requests within 48 hours (aim for immediate suppression).

Minimal Nodemailer setup

Use a transport that already aligns SPF/DKIM/DMARC (SMTP Zen or your relay). Then add headers to each message or via defaults.

import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: 465,
  secure: true,
  auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS }
});

const listId = "abcd1234"; // signed token mapping to recipient+list

await transporter.sendMail({
  from: '"Product Updates" <[email protected]>',
  to: "[email protected]",
  subject: "Service notice",
  text: "Plain text body",
  html: "<p>HTML body with visible unsubscribe link below.</p>",
  headers: {
    "List-Unsubscribe": `<https://example.com/unsub/${listId}>, <mailto:[email protected]?subject=unsubscribe>`,
    "List-Unsubscribe-Post": "List-Unsubscribe=One-Click"
  }
});

Notes:

  • Keep the body unsubscribe link visible. Hiding it raises complaints.
  • The HTTPS endpoint must accept POST without login, cookies, or CSRF and return a successful response quickly.
  • Do not expose raw emails in the URL; use signed tokens.

Avoid duplicating headers by configuring transporter.set in Nodemailer 6.x:

transporter.set("headers", {
  "List-Unsubscribe-Post": "List-Unsubscribe=One-Click"
});

Still set List-Unsubscribe per message, because the token must map to the recipient.

Handling the one-click endpoint

  • Accept POST with List-Unsubscribe=One-Click; reserve GET for a human-facing preference page.
  • Immediately suppress the address from the list represented by the token.
  • Keep essential transactional messages in a separate mailstream.
  • Log timestamp, token/list, and IP for auditability.

Testing checklist

  • Send a test to Gmail and Yahoo; verify both headers exist in “Show original.”
  • Click the HTTPS link; confirm instant suppression and a 200 response.
  • Fire a follow-up test within 24 hours; the unsubscribed recipient must be excluded.
  • Monitor complaint rates; aim for <0.1%.

Where SMTP Zen helps

SMTP Zen handles authentication and safe SMTP delivery. Add the headers above in Nodemailer, point the links to your suppression logic, and you stay compliant without adopting a marketing platform.

  • Pro SMTP
    High-deliverability SMTP for products at scale, unlimited domains, and priority support.
    $11.99
     /month
    Usage
    Domain Names
    Unlimited
    Mailboxes
    20
    Bandwidth
    Unlimited
    Email Forwarders / Alias
    10
    Base Disk Quota
    20GB
    Features
    Backups
    "Catch All" Emails
    Advanced Spam Filter
    SSL
    Priority Support
  • Freelancer SMTP
    Reliable, no fuss SMTP service for client work - custom domains, forwarding, and more.
    $5.99
     /month
    Usage
    Domain Names
    Unlimited
    Mailboxes
    10
    Bandwidth
    Unlimited
    Email Forwarders / Alias
    10
    Base Disk Quota
    10GB
    Features
    Backups
    "Catch All" Emails
    Advanced Spam Filter
    SSL
    Priority Support
  • Starter SMTP
    Simple, dependable SMTP to ship transactional emails - no fuss, ready in minutes.
    $2.99
     /month
    Usage
    Domain Names
    Unlimited
    Mailboxes
    5
    Bandwidth
    Unlimited
    Email Forwarders / Alias
    10
    Base Disk Quota
    5GB
    Features
    Backups
    "Catch All" Emails
    Advanced Spam Filter
    SSL
    Priority Support
  • Roll your own
    Your plan, your rules. Tailored plan just for you. Fully customizable.
    $1.2
     /month
    Usage
    Domain Names
    Unlimited
    Mailboxes
    1
    Bandwidth
    Unlimited
    Email Forwarders / Alias
    1
    Base Disk Quota
    2GB
    Features
    Backups
    "Catch All" Emails
    Advanced Spam Filter
    SSL
    Priority Support