Bỏ qua, đến nội dung

@digiforce-nc/plugin-notification-email

Plugin cung cấp kênh thông báo email (SMTP) — đăng ký channel type email vào notification-manager, gửi email qua nodemailer.

Plugin này làm gì?

Plugin đăng ký kênh email vào hệ thống notification-manager. Khi có yêu cầu gửi thông báo qua email, notification-manager dispatch đến MailNotificationChannel, channel này dùng nodemailer để gửi email qua SMTP server đã cấu hình.

Ba nhiệm vụ chính

#Nhiệm vụChi tiết
1Đăng ký kênh emailĐăng ký channel type email + MailNotificationChannel vào notification-manager
2Gửi email qua SMTPDùng nodemailer tạo transporter, gửi email với subject, body, attachments
3Cung cấp UI cấu hìnhForms: cấu hình SMTP, chọn người nhận, soạn nội dung email

Kiến trúc

Tổng quan

TầngVai tròThành phần
ChannelLogic gửi emailMailNotificationChannel
TransportKết nối SMTPnodemailer transporter
UICấu hình SMTP, soạn messageConfigForm, MessageConfigForm, ContentConfigForm
ManagerDispatch và ghi lognotification-manager (dependency)

Luồng gửi email

Cấu hình SMTP

Thông tin SMTP được lưu trong options của notificationChannels:

FieldMô tảVí dụ
hostSMTP server hostnamesmtp.gmail.com
portPort kết nối587 (TLS) hoặc 465 (SSL)
secureDùng SSLtrue cho port 465
accountTài khoản xác thựcnoreply@company.com
passwordMật khẩu hoặc app password****
fromĐịa chỉ gửi mặc địnhDigiForce <noreply@company.com>

Vòng đời plugin

Quan hệ với notification-manager

Plugin này không hoạt động độc lập — nó là "adapter" cho notification-manager:

  • notification-manager cung cấp: registry, dispatch, logging, UI framework
  • notification-email cung cấp: logic gửi SMTP, UI cấu hình riêng cho email

Ví dụ sử dụng

Cấu hình SMTP channel qua UI

  1. Vào Settings → Notification Channels
  2. Tạo channel mới, chọn type = "email"
  3. Điền SMTP host, port, account, password
  4. Test connection
  5. Lưu cấu hình

Gửi email qua API

typescript
await agent.resource('messages').send({
  values: {
    channelName: 'smtp-channel',
    to: ['user@example.com'],
    subject: 'Thong bao he thong',
    content: '<h1>Xin chao</h1><p>Noi dung email...</p>',
  },
});

Gửi email từ workflow

Trong workflow node "Send Notification":

  • Chọn channel: email channel đã cấu hình
  • Người nhận: biến từ workflow context
  • Nội dung: template với biến động

Thành phần client

Thành phầnMô tả
ConfigFormForm cấu hình SMTP (host, port, account, password, from)
MessageConfigFormForm chọn người nhận (to, cc, bcc)
ContentConfigFormForm soạn nội dung email (subject, body HTML)

Dependencies

PackageVai trò
nodemailerThư viện gửi email qua SMTP
@digiforce-nc/plugin-notification-managerHub thông báo trung tâm (peer dependency bắt buộc)
@digiforce-nc/serverServer framework
@digiforce-nc/clientClient framework — UI components

Mục lục chi tiết