webiny-mailer-smtp
它能做什么
展示如何将 Webiny 项目连接到 SMTP 邮件服务器以发送邮件。适用于需要设置邮件发送或修复邮件无法送达问题的开发者。
适用场景
- ✓开发者想在 Webiny 项目中设置 SMTP 邮件投递的时候。
- ✓开发者的 Webiny 项目无法发送邮件的时候。
- ✓开发者需要更改 Webiny 邮件的发件人地址或回复地址的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/mailer-smtp/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“如何设置 SMTP,让我的 Webiny 项目能够发送邮件?”
每周 5 个新技能,1 分钟读完。
工作原理
该技能提供一个代码示例,包含服务器、端口、登录信息和发件人详情。它强调将密码保存在环境变量中,并提醒你在修改后部署 API。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Mailer SMTP Configuration
TL;DR
Add <Api.Mailer.Smtp ... /> to your webiny.config.tsx to configure SMTP email delivery at build time. The component serializes the settings into the build artifact — always pass the password via an environment variable, never hard-code it. Deploy the API after making changes.
Core Pattern
import { Api } from "webiny/extensions";
<Api.Mailer.Smtp
host={"smtp.example.com"}
port={587}
user={"smtp-user"}
password={process.env.SMTP_PASSWORD!}
from={"noreply@example.com"}
replyTo={"support@example.com"} {/* optional */}
/>
Place this inside the JSX returned by your config component in webiny.config.tsx, alongside other <Api.*> extensions.
Props Reference
| Prop | Type | Required | Description |
|---|---|---|---|
host |
string |
Yes | SMTP server hostname |
port |
number |
Yes | SMTP server port (positive integer) |
user |
string |
Yes | SMTP authentication username |
password |
string |
Yes | SMTP authentication password — use env var |
from |
string |
Yes | Default sender address |
replyTo |
string |
No | Default reply-to address |
from and replyTo are validated by the email-addresses package against RFC 5322.
Full Example (webiny.config.tsx)
import React from "react";
import { Api, Admin, Core } from "webiny/extensions";
const MyConfig = () => {
return (
<>
{/* ... other extensions ... */}
{/* Mailer: configure SMTP transport via code */}
<Api.Mailer.Smtp
host={"smtp.sendgrid.net"}
port={587}
user={"apikey"}
password={process.env.SENDGRID_API_KEY!}
from={"noreply@acme.com"}
replyTo={"support@acme.com"}
/>
</>
);
};
Add SENDGRID_API_KEY=your-secret to your .env file (never commit it).
Common Mistakes
| Mistake | Fix |
|---|---|
| Hard-coding the password | Use process.env.SMTP_PASSWORD! |
process.env.SMTP_PASSWORD undefined at build time → "expected string, received object" error |
Ensure the env var is set before deploying |
from/replyTo value fails validation |
Must be a valid RFC 5322 mailbox address |
| Settings not taking effect | Run yarn webiny build api after editing webiny.config.tsx |
Quick Reference
# After editing webiny.config.tsx, build the API
yarn webiny build api
Note: This command only works in a
devenvironment. For other environments, runyarn webiny build api --env=YOUR_ENVinstead.
// Environment variable in .env
SMTP_PASSWORD = your - smtp - password - here;
Related Skills
webiny-project-structure— Wherewebiny.config.tsxlives and how extensions are structuredwebiny-local-development— Running and deploying locally
常见问题
SMTP 设置放在哪里?
在 webiny.config.tsx 文件中,放在返回其他 API 设置的代码内。
为什么不应该把密码直接写进代码?
该技能警告,设置会被保存到构建结果中,因此直接输入的密码会被存储在那里。使用环境变量可以让密码不出现在代码中。
哪些设置是必需的?
主机、端口、用户、密码和发件人地址是必需的。回复地址是可选的。
详情
作者的原始描述
Use when configuring SMTP email/mailer settings in a Webiny project. Triggers on: "configure email", "set up SMTP", "mailer config", "sending emails", "email not working", "configure mailer", "SMTP password", "Api.Mailer.Smtp".
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12615
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。