Giao diện
@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 |
| 2 | Gửi email qua SMTP | Dùng nodemailer tạo transporter, gửi email với subject, body, attachments |
| 3 | Cung cấp UI cấu hình | Forms: 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ầng | Vai trò | Thành phần |
|---|---|---|
| Channel | Logic gửi email | MailNotificationChannel |
| Transport | Kết nối SMTP | nodemailer transporter |
| UI | Cấu hình SMTP, soạn message | ConfigForm, MessageConfigForm, ContentConfigForm |
| Manager | Dispatch và ghi log | notification-manager (dependency) |
Luồng gửi email
Cấu hình SMTP
Thông tin SMTP được lưu trong options của notificationChannels:
| Field | Mô tả | Ví dụ |
|---|---|---|
host | SMTP server hostname | smtp.gmail.com |
port | Port kết nối | 587 (TLS) hoặc 465 (SSL) |
secure | Dùng SSL | true cho port 465 |
account | Tài khoản xác thực | noreply@company.com |
password | Mật khẩu hoặc app password | **** |
from | Địa chỉ gửi mặc định | DigiForce <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
- Vào Settings → Notification Channels
- Tạo channel mới, chọn type = "email"
- Điền SMTP host, port, account, password
- Test connection
- 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ần | Mô tả |
|---|---|
ConfigForm | Form cấu hình SMTP (host, port, account, password, from) |
MessageConfigForm | Form chọn người nhận (to, cc, bcc) |
ContentConfigForm | Form soạn nội dung email (subject, body HTML) |
Dependencies
| Package | Vai trò |
|---|---|
nodemailer | Thư viện gửi email qua SMTP |
@digiforce-nc/plugin-notification-manager | Hub thông báo trung tâm (peer dependency bắt buộc) |
@digiforce-nc/server | Server framework |
@digiforce-nc/client | Client framework — UI components |