This commit is contained in:
yun
2026-08-15 01:38:05 +08:00
parent 139330aee2
commit eb8f660ab5
57 changed files with 5401 additions and 1438 deletions
+28 -28
View File
@@ -1,29 +1,29 @@
// Package mailx 是一个简单易用的多通道邮件发送库。
//
// 核心特性:
// - 多通道支持:smtp / 阿里云 / AWS SES / mailgun 等,可自由扩展
// - 链式消息构建:mailx.NewMessage().From(...).To(...).Subject(...).Build()
// - 通道管理器:注册多个通道,发送时按名称路由或临时指定配置
// - 发送时指定配置:SendWith 选已注册通道,SendBy 直接传入带配置的通道
//
// 快速开始:
//
// ctx := context.Background()
//
// // 方式一:直接使用单个通道
// err := smtp.New(smtp.Config{Host: "...", Port: 465, User: "...", Password: "..."}).
// Send(ctx, mailx.NewMessage().
// From("a@example.com").
// To("b@example.com").
// Subject("hello").
// Body("world").
// Build())
//
// // 方式二:多通道管理器,发送时切换通道
// mgr := mailx.NewManager()
// mgr.Register(smtp.New(...))
// mgr.Register(aliyun.New(...))
// mgr.Send(ctx, msg) // 默认通道
// mgr.SendWith(ctx, "aliyun", msg) // 指定通道
// mgr.SendBy(ctx, mailgun.New(...), msg) // 临时指定配置的通道
package mailx
import (
"code.yun.ink/pkg/mailx/aliyun"
"code.yun.ink/pkg/mailx/aws"
"code.yun.ink/pkg/mailx/interfaces"
"code.yun.ink/pkg/mailx/mailgun"
"code.yun.ink/pkg/mailx/smtp"
)
var Platform interfaces.EmailFactoryInterface
// 注册
func init() {
Platform = interfaces.NewDefaultEmailFactory()
// 阿里
Platform.Register(aliyun.NewAliyun())
// AWS
Platform.Register(aws.NewAws())
// Smtp
Platform.Register(smtp.NewSmtp())
// mailgun
Platform.Register(mailgun.NewMailGun())
}