跳到正文
Skillpedia
API 与服务器(后端)8.1k · #12615

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/mailer-smtp/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 dev environment. For other environments, run yarn webiny build api --env=YOUR_ENV instead.

// Environment variable in .env
SMTP_PASSWORD = your - smtp - password - here;

Related Skills

  • webiny-project-structure — Where webiny.config.tsx lives and how extensions are structured
  • webiny-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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能