深化smtp文件的支持

This commit is contained in:
Yun
2025-11-21 14:01:43 +08:00
parent f2b8345e93
commit b3a87d0b54
16 changed files with 2075 additions and 200 deletions
+33 -11
View File
@@ -41,20 +41,42 @@ type EmialConfigDataAliyun struct {
ReplyAddress string `json:"reply_address"` // 邮件回复地址
}
type ContentType string
const (
ContentTypeText ContentType = "text"
ContentTypeHTML ContentType = "html"
ContentTypeAuto ContentType = "auto" // 自动检测
)
type AttachmentType string
const (
AttachmentTypeFile AttachmentType = "file" // 普通附件
AttachmentTypeInline AttachmentType = "inline" // 内嵌图片
)
type Message struct {
Form string
To []string
Cc []string
Bcc []string
Subject string
Body string
ReplyTo string
Attachment []MessageAttachment // 附件
Form string
To []string
Cc []string
Bcc []string
Subject string
Body string // 邮件内容
BodyType ContentType // 内容类型:text/html/auto
TextBody string // 纯文本版本(可选)
ReplyTo string
Attachment []Attachment // 普通附件
InlineImage []Attachment // 内嵌图片
}
type MessageAttachment struct {
Content string
ContentType string
type Attachment struct {
Content string // 文件路径或内容
ContentType string // MIME类型
Name string // 文件名
CID string // Content-ID(内嵌图片用)
Type AttachmentType // 附件类型
Data []byte // 直接提供字节数据(可选)
}
type EmailSendRecord struct {
+1 -1
View File
@@ -22,7 +22,7 @@ type EmailFactoryInterface interface {
}
type DefaultEmail struct {
Options EmailOption
Options Options // 配置信息
EmailType EmailType
}
+9 -9
View File
@@ -6,7 +6,7 @@ import (
"github.com/yuninks/loggerx"
)
type EmailOption struct {
type Options struct {
Logger loggerx.LoggerInterface
Smtp *EmailConfigDataSmtp `json:"smtp,omitempty"` // smtp
@@ -15,42 +15,42 @@ type EmailOption struct {
Mailgun *EmialConfigDataMailgun `json:"mailgun,omitempty"` // mailgun
}
func DefaultOptions() EmailOption {
func DefaultOptions() Options {
ctx := context.Background()
return EmailOption{
return Options{
Logger: loggerx.NewLogger(ctx),
}
}
type Option func(*EmailOption)
type Option func(*Options)
// 设置日志
func SetLogger(logger loggerx.LoggerInterface) Option {
return func(o *EmailOption) {
return func(o *Options) {
o.Logger = logger
}
}
func SetSmtp(smtp *EmailConfigDataSmtp) Option {
return func(o *EmailOption) {
return func(o *Options) {
o.Smtp = smtp
}
}
func SetAws(aws *EmailConfigDataAws) Option {
return func(o *EmailOption) {
return func(o *Options) {
o.Aws = aws
}
}
func SetAliyun(aliyun *EmialConfigDataAliyun) Option {
return func(o *EmailOption) {
return func(o *Options) {
o.Aliyun = aliyun
}
}
func SetMailgun(mailgun *EmialConfigDataMailgun) Option {
return func(o *EmailOption) {
return func(o *Options) {
o.Mailgun = mailgun
}
}