支持邮箱里保存着一整年的产品反馈,但很少有人会从头读完;抽样摘要也容易漏掉散布在数百封邮件中的趋势。Gemini 4 Neon 的上下文最多可达一百万 token,因此能够一次阅读全年内容。本教程从 IaGenify 邮箱提取邮件,构建长输入,再要求模型给出有证据支撑的洞察。
收集全年邮件
`messages.list()` 会按页读取文件夹,并从最新邮件开始。游标是日期,因此读取期间新到的邮件不会改变页面位置。摘要不包含邮件正文,所以还要通过 `messages.get()` 读取每封邮件。
import { IaGenify } from "iagenify";
const api = new IaGenify({ apiKey: process.env.IAGENIFY_API_KEY });
const box = await api.mail.get("[email protected]");
const since = new Date("2026-01-01");
const mails = [];
let cursor = null;
collect: do {
const page = await box.messages.list({ folder: "inbox", limit: 100, cursor });
for (const summary of page.messages) {
if (new Date(summary.receivedAt) < since) break collect;
const message = await box.messages.get(summary.id);
mails.push(`[${summary.id}] ${summary.receivedAt} — ${message.subject}\n${message.text}`);
}
cursor = page.nextCursor;
} while (cursor);发送前估算规模
大约四个字符相当于一个 token。先测量邮件文本:超过一百万 token 的请求会在扣费前被拒绝;远低于上限时,也能据此估算费用。
const corpus = mails.join("\n\n---\n\n");
const tokens = Math.ceil(corpus.length / 4);
const [neon] = (await api.catalogue()).filter((row) => row.model === "gemini-4-neon");
console.log(tokens, "tokens ≈", Math.ceil((tokens / 1e6) * neon.creditsInput), "credits of input");要求洞察附带证据
const turn = await api.models.turn({
model: "gemini-4-neon",
system: "You analyse customer email for a product team. Every insight cites the message ids that show it.",
messages: [{
role: "user",
content: `${corpus}\n\nList the ten most important product insights from this year of support email. For each: one sentence, how often it appears, and three message ids that show it.`,
}],
maxOutputTokens: 8000,
});
console.log(turn.message.content, turn.usage.credits);邮件 ID 让每项洞察都可以打开原文核对。根据发现采取行动前,先抽查几封原始邮件。
费用
Neon 每百万输入 token 收取 750 额度,每百万输出 token 收取 3,750 额度;1 个额度等于 1 美分。一年邮件若约有 40 万 token,输入费用约为 300 个额度。因此可按季度运行分析,而不必每收到一封邮件就运行。
参考资料
常见问题
为什么不分批总结邮件?
每个批次只能看到自己的部分。只有让模型一起阅读数百封邮件,才能发现跨邮件的共同趋势。
可以使用其他邮件服务商吗?
本例通过 SDK 读取 IaGenify 邮箱。其他来源的邮件也可以用同样方式作为文本传入。