Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)8.1k · #12615

webiny-mailer-smtp

Skill này làm gì

Chỉ cách kết nối dự án Webiny với máy chủ email SMTP để có thể gửi email. Dành cho lập trình viên cần thiết lập gửi email hoặc sửa các email không đến nơi.

Khi nào nên dùng

  • ✓Khi lập trình viên muốn thiết lập gửi email SMTP trong dự án Webiny.
  • ✓Khi email từ dự án Webiny không được gửi đi.
  • ✓Khi lập trình viên cần đổi địa chỉ người gửi hoặc địa chỉ trả lời cho email Webiny.

Liên kết skill

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/mailer-smtp/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/mailer-smtp/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để thiết lập SMTP để dự án Webiny của tôi có thể gửi email?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill đưa ra một ví dụ code với máy chủ, cổng, tài khoản đăng nhập và thông tin người gửi. Skill nhấn mạnh việc lưu mật khẩu trong biến môi trường và nhắc bạn triển khai API sau khi thay đổi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Tôi đặt cài đặt SMTP ở đâu?

Trong file webiny.config.tsx, bên trong đoạn code trả về các cài đặt API khác.

Vì sao không nên gõ mật khẩu thẳng vào code?

Skill cảnh báo rằng cài đặt được lưu vào bản build, nên mật khẩu gõ thẳng sẽ bị lưu ở đó. Biến môi trường giúp giữ mật khẩu ngoài code.

Những cài đặt nào là bắt buộc?

Host, cổng, người dùng, mật khẩu và địa chỉ gửi là bắt buộc. Địa chỉ trả lời là tùy chọn.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
8.1k
Vị trí xếp hạng
#12615
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự