Skills2026年5月16日·1 分钟阅读

Nodemailer — Send Emails from Node.js with Ease

The de facto email sending library for Node.js, supporting SMTP, OAuth2, HTML templates, and attachments with a simple unified API.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Nodemailer Overview
直接安装命令
npx -y tokrepo@latest install a11d7b90-50fe-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Nodemailer is the most widely used email sending module for Node.js, handling SMTP connections, authentication, and message composition. It abstracts away transport complexities so developers can send transactional emails, notifications, and reports with minimal configuration.

What Nodemailer Does

  • Connects to any SMTP server with support for STARTTLS, direct TLS, and custom ports
  • Sends HTML and plain-text emails with inline images, attachments, and embedded CID references
  • Supports OAuth2 authentication for Gmail, Outlook, and other providers
  • Provides connection pooling for high-throughput email delivery
  • Includes a built-in test account generator via Ethereal for development and CI

Architecture Overview

Nodemailer separates concerns into transports and message composition. The transport layer manages TCP connections, TLS negotiation, and SMTP command sequences. The message layer handles MIME multipart construction, header encoding, and attachment streaming. Plugins can intercept the message pipeline to add DKIM signatures, transform HTML to text, or log outgoing messages.

Self-Hosting & Configuration

  • Install from npm with zero native dependencies — pure JavaScript
  • Configure transports via an options object or a connection URL string
  • Enable connection pooling with pool: true for batch sends
  • Use nodemailer.createTestAccount() to get disposable Ethereal credentials during development
  • Add DKIM signing by passing dkim options with domain, key selector, and private key

Key Features

  • Unicode-safe — handles international email addresses and encoded headers
  • Stream-based attachments for sending large files without buffering in memory
  • Calendar event support via iCalendar (ICS) attachments with method headers
  • Proxy support including SOCKS4/5 and HTTP CONNECT for restricted networks
  • Over 17,500 GitHub stars and 8 million weekly npm downloads

Comparison with Similar Tools

  • SendGrid SDK — managed delivery with analytics; Nodemailer works with any SMTP provider directly
  • AWS SES SDK — vendor-locked to Amazon; Nodemailer is transport-agnostic
  • Resend — modern API-first service; Nodemailer gives full SMTP control and offline testing
  • email.js — browser-side email via SMTP.js proxy; Nodemailer runs server-side with full auth
  • Postal — self-hosted mail server; Nodemailer is a client library, not a server

FAQ

Q: Does Nodemailer work with Gmail? A: Yes. Use OAuth2 credentials or an App Password. Gmail rate-limits free accounts to around 500 emails per day.

Q: Can I send bulk emails with Nodemailer? A: It supports connection pooling for throughput, but for large campaigns consider a dedicated service with bounce handling and reputation management.

Q: How do I test emails locally without a real SMTP server? A: Use nodemailer.createTestAccount() to get Ethereal credentials, then view sent messages in the Ethereal web interface.

Q: Is it compatible with ESM and TypeScript? A: Yes. Nodemailer ships CommonJS with bundled TypeScript declarations. Import via import nodemailer from 'nodemailer' with appropriate module settings.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产