@absolutejs/email

中文文档
0.11.0发布于 2026/11/07BSL-1.1TypeScriptES Module近 30 天下载 3642

Provider-neutral email sync and inbound adapters for AbsoluteJS: Gmail, Microsoft Graph, IMAP, and Resend Inbound.

原始使用文档
文档目录7 节
  1. Tool-confined verification codes
  2. Install
  3. Gmail
  4. Microsoft Graph
  5. Inbound mail (Resend)
  6. IMAP
  7. Host-controlled Gmail sending

@absolutejs/email

The Gmail adapter can also locate a tagged delivery canary across Inbox, Spam, Trash, and other labels with findGmailMessagePlacement. The host application owns canary scheduling, mailbox credentials, alert policy, and persistence.

Provider-neutral email sync adapters for AbsoluteJS applications.

This package owns the provider mechanics:

  • Gmail REST sync, users.watch, and Pub/Sub payload parsing
  • Microsoft Graph message delta sync and subscription notification parsing
  • IMAP over TLS for custom mailbox providers
  • Normalized message shapes that host apps can persist, score, filter, or enrich

Host applications own product policy:

  • user consent and privacy controls
  • credential storage
  • business-specific relevance scoring
  • database persistence
  • queue scheduling and UI

Tool-confined verification codes

@absolutejs/email/verification provides deterministic Gmail, Microsoft Graph, and IMAP lookups plus a strict parser for Agent Exchange source adapters. It is a library API, deliberately absent from the package's model-facing manifest tools.

The main verification entry point is browser-safe for Gmail and Microsoft Graph. Import the server-only IMAP lookup from @absolutejs/email/verification/imap so browser bundles never pull in Node TLS or imapflow.

Profiles bind a mailbox lookup to exact HTTPS origins, provider names, sender addresses, trusted RFC 8601 authentication services, aligned DMARC results, subject markers, body markers, a short time window, and one code length. Retrieval fails closed on missing or duplicated authentication evidence, unavailable candidates, excessive candidate/body sizes, no match, more than one matching message, or more than one marker-bound code occurrence.

import {
  createGmailVerificationMessageLookup,
  retrieveEmailVerificationCode,
} from "@absolutejs/email/verification";

const result = await retrieveEmailVerificationCode(
  createGmailVerificationMessageLookup({ accountEmail, client: gmail }),
  {
    accountEmail,
    expectedOrigin: "https://accounts.example.com",
    notBefore: new Date(requestCreatedAt),
    notAfter: new Date(requestExpiresAt),
    profile: {
      bodyMarkers: ["verification code"],
      id: "accounts-example-six-digit-v1",
      origins: ["https://accounts.example.com"],
      providers: ["gmail"],
      senderAddresses: ["[email protected]"],
      senderAuthentication: {
        allowedHeaderFromDomains: ["example.com"],
        trustedAuthservIds: ["mx.mailbox.example"],
      },
      subjectIncludesAny: ["sign in"],
    },
  },
);

// Pass result.bytes directly to a trusted sink or E2EE envelope. Do not stringify
// it, log it, add it to a prompt, or return it from an agent tool.
result.bytes.fill(0);

trustedAuthservIds is deployment-specific. Configure only the authserv-id inserted inside your mailbox provider's trusted boundary; never copy an untrusted Authentication-Results header from farther upstream. The required DMARC pass must align exactly with both the visible sender domain and an allowlisted domain. For cross-agent requests, also pass an unpredictable request challenge through requiredBodyText; time-only correlation is weaker.

Email codes remain bearer values and are not phishing-resistant. Prefer OAuth, passkeys, or provider-native delegated actions whenever the upstream service supports them.

Install

bun add @absolutejs/email

Gmail

import {
  createGmailClient,
  gmailMessagesToNormalized,
  parseGmailPubSubWebhook,
} from "@absolutejs/email";

const client = createGmailClient({ accessToken });
const { messages, cursor } = await client.listHistory({ cursor: historyId });
const normalized = await gmailMessagesToNormalized(client, messages, {
  accountEmail: "[email protected]",
});

Microsoft Graph

import {
  createMicrosoftGraphEmailClient,
  microsoftMessagesToNormalized,
} from "@absolutejs/email";

const client = createMicrosoftGraphEmailClient({ accessToken });
const { messages, cursor } = await client.listDelta();
const normalized = microsoftMessagesToNormalized(messages, {
  accountEmail: "[email protected]",
});

Inbound mail (Resend)

Resend's email.received webhook carries metadata only; the body and headers come from the receiving API. resolveResendInboundEmail does both and returns a provider-neutral InboundEmailMessage. stripQuotedReply isolates the sender's own words (quoted history, signatures, mobile sign-offs and Outlook header blocks removed) so a host can act on a reply or preview it.

import { resolveResendInboundEmail, stripQuotedReply } from "@absolutejs/email";

const email = await resolveResendInboundEmail(resendApiKey, webhookBody);
if (email) {
  const alias = email.to.find((to) => to.address.startsWith("r+"));
  const words = stripQuotedReply(email.text, { maxLength: 4000 });
  // route by alias, dedupe on email.emailId, thread on email.inReplyTo
}

IMAP

import { fetchImapMessages } from "@absolutejs/email";

const result = await fetchImapMessages({
  accountEmail: "[email protected]",
  auth: { pass: appPassword, user: "[email protected]" },
  host: "imap.fastmail.com",
  port: 993,
  secure: true,
});

Verification profiles may opt into codeLayout: "standalone-after-marker" for messages that display the code on its own line after introductory text. An exact configured body marker must precede the code within 512 characters. Multiple codes or matching messages remain ambiguous and fail closed. Sender authentication, recipient, service origin, subject, time window and candidate limits still apply. Gmail and Microsoft HTML normalization preserves block boundaries for this layout. The default layout remains a code immediately following its configured marker.

Host-controlled Gmail sending

sendGmailMessage(message, { fetch, signal }) sends a plain-text MIME message with up to five attachments (10 MB total). Bind fetch to host-authorized credentials and egress; the package never obtains credentials or grants approval. buildOutgoingMime is available for inspection. Supply a stable RFC Message-ID, and both threadId and inReplyTo for replies.

Sending is a single attempt. EmailSendError.outcome distinguishes explicit rejection from unknown; never automatically retry an unknown send. Gmail's Message-ID is for reconciliation, not an idempotency guarantee. Hosts must gate exact input through approval and use durable execution before invoking this API.

版本与发布记录

@absolutejs/email 共发布 22 个版本,首次发布于 2026/06/17;过去 12 个月发布了 22 个版本。

版本发布日期距今
0.11.0latest2026/11/07今天
0.10.02026/11/07今天
0.9.02026/11/061 天前
0.8.02026/11/052 天前
0.7.12026/10/0929 天前
0.4.1maintenance-0.42026/09/271 个月前

关于 @absolutejs/email 的常见问题

@absolutejs/email 是什么?

Provider-neutral email sync and inbound adapters for AbsoluteJS: Gmail, Microsoft Graph, IMAP, and Resend Inbound.

如何安装 @absolutejs/email?

在项目目录运行 npm install @absolutejs/email,或使用 pnpm add / yarn add / bun add。

@absolutejs/email 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@absolutejs/email 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@absolutejs/email 可以商用吗?

@absolutejs/email 使用 BSL-1.1 许可。声明的许可为 BSL-1.1,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@absolutejs/email 的下载量有多少?

根据 npm 官方下载统计,@absolutejs/email 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,642 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@absolutejs/email 还在维护吗?

最新版本 0.11.0 发布于 2026/11/07(今天);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2026/06/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。