支持多版本
This commit is contained in:
@@ -0,0 +1,66 @@
|
|||||||
|
package interfaces
|
||||||
|
|
||||||
|
type EmialConfigDataMailgun struct {
|
||||||
|
ApiKey string `json:"api_key"` // mailgun api key
|
||||||
|
Domain string `json:"domain"` // mailgun domain
|
||||||
|
Sender string `json:"sender"` // 发件人
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailConfigDataSmtp struct {
|
||||||
|
Username string `json:"username"` // 邮箱账号
|
||||||
|
Password string `json:"password"` // 授权码
|
||||||
|
Host string `json:"host"` // SMTP 服务器【默认smtpdm.aliyun.com】
|
||||||
|
Port string `json:"port"` // 发信端口
|
||||||
|
ReplyTo string `json:"reply_to"` // 【选填】回复地址
|
||||||
|
// From string `json:"from"` // 【选填】阿里云邮箱发件人
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailConfigDataAws struct {
|
||||||
|
AccessId string `json:"access_id"` // 亚马逊AccessId
|
||||||
|
AccessSecret string `json:"access_secret"` // 亚马逊AccessSecret
|
||||||
|
Region string `json:"region"` // 亚马逊Region
|
||||||
|
Sender string `json:"sender"` // 亚马逊发件人
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmialConfigDataAliyun struct {
|
||||||
|
AccessId string `json:"access_id"` // 阿里云AccessId
|
||||||
|
AccessKey string `json:"access_key"` // 阿里云AccessKey
|
||||||
|
Endpoint string `json:"endpoint"` // 区域 默认dm.aliyuncs.com
|
||||||
|
AccountName string `json:"account_name"` // 账号名
|
||||||
|
ReplyAddress string `json:"reply_address"` // 邮件回复地址
|
||||||
|
}
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Form string
|
||||||
|
To []string
|
||||||
|
Cc []string
|
||||||
|
Bcc []string
|
||||||
|
Subject string
|
||||||
|
Body string
|
||||||
|
ReplyTo string
|
||||||
|
Attachment []MessageAttachment // 附件
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageAttachment struct {
|
||||||
|
Content string
|
||||||
|
ContentType string
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailSendRecord struct {
|
||||||
|
AccountName string // 发件人
|
||||||
|
UpdateTime int64 // 毫秒时间戳
|
||||||
|
Status EmailSendStatus // 状态
|
||||||
|
ToUser string // 收件人
|
||||||
|
Subject string // 邮件主题
|
||||||
|
ErrorMessage string // 错误信息
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmailSendStatus int
|
||||||
|
|
||||||
|
const (
|
||||||
|
EmailSendStatusUnknown EmailSendStatus = 0
|
||||||
|
EmailSendStatusSuccess EmailSendStatus = 1
|
||||||
|
EmailSendStatusInvalidAddress EmailSendStatus = 2
|
||||||
|
EmailSendStatusSpam EmailSendStatus = 3
|
||||||
|
EmailSendStatusFailed EmailSendStatus = 4
|
||||||
|
)
|
||||||
@@ -3,94 +3,25 @@ package interfaces
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/yuninks/loggerx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Email interface {
|
type Email interface {
|
||||||
InitEmail(ctx context.Context, params EmailConfigData,logger loggerx.LoggerInterface) (Email, error)
|
InitEmail(ctx context.Context, opt ...Option) (Email, error)
|
||||||
// Send 发送邮件
|
// Send 发送邮件
|
||||||
Send(ctx context.Context, params Message) error
|
Send(ctx context.Context, params Message) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmailConfigData struct {
|
|
||||||
Smtp *EmailConfigDataSmtp `json:"smtp,omitempty"` // smtp
|
|
||||||
Aws *EmailConfigDataAws `json:"aws,omitempty"` // 亚马逊
|
|
||||||
Aliyun *EmialConfigDataAliyun `json:"aliyun,omitempty"` // 阿里云
|
|
||||||
Mailgun *EmialConfigDataMailgun `json:"mailgun,omitempty"` // mailgun
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmialConfigDataMailgun struct {
|
|
||||||
ApiKey string `json:"api_key"` // mailgun api key
|
|
||||||
Domain string `json:"domain"` // mailgun domain
|
|
||||||
Sender string `json:"sender"` // 发件人
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmailConfigDataSmtp struct {
|
|
||||||
Username string `json:"username"` // 邮箱账号
|
|
||||||
Password string `json:"password"` // 授权码
|
|
||||||
Host string `json:"host"` // SMTP 服务器【默认smtpdm.aliyun.com】
|
|
||||||
Port string `json:"port"` // 发信端口
|
|
||||||
ReplyTo string `json:"reply_to"` // 【选填】回复地址
|
|
||||||
// From string `json:"from"` // 【选填】阿里云邮箱发件人
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmailConfigDataAws struct {
|
|
||||||
AccessId string `json:"access_id"` // 亚马逊AccessId
|
|
||||||
AccessSecret string `json:"access_secret"` // 亚马逊AccessSecret
|
|
||||||
Region string `json:"region"` // 亚马逊Region
|
|
||||||
Sender string `json:"sender"` // 亚马逊发件人
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmialConfigDataAliyun struct {
|
|
||||||
AccessId string `json:"access_id"` // 阿里云AccessId
|
|
||||||
AccessKey string `json:"access_key"` // 阿里云AccessKey
|
|
||||||
Endpoint string `json:"endpoint"` // 区域 默认dm.aliyuncs.com
|
|
||||||
AccountName string `json:"account_name"` // 账号名
|
|
||||||
ReplyAddress string `json:"reply_address"` // 邮件回复地址
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Form string
|
|
||||||
To []string
|
|
||||||
Cc []string
|
|
||||||
Bcc []string
|
|
||||||
Subject string
|
|
||||||
Body string
|
|
||||||
ReplyTo string
|
|
||||||
Attachment []MessageAttachment // 附件
|
|
||||||
}
|
|
||||||
|
|
||||||
type MessageAttachment struct {
|
|
||||||
Content string
|
|
||||||
ContentType string
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmailSendRecord struct {
|
|
||||||
AccountName string // 发件人
|
|
||||||
UpdateTime int64 // 毫秒时间戳
|
|
||||||
Status EmailSendStatus // 状态
|
|
||||||
ToUser string // 收件人
|
|
||||||
Subject string // 邮件主题
|
|
||||||
ErrorMessage string // 错误信息
|
|
||||||
}
|
|
||||||
|
|
||||||
type EmailSendStatus int
|
|
||||||
|
|
||||||
const (
|
|
||||||
EmailSendStatusUnknown EmailSendStatus = 0
|
|
||||||
EmailSendStatusSuccess EmailSendStatus = 1
|
|
||||||
EmailSendStatusInvalidAddress EmailSendStatus = 2
|
|
||||||
EmailSendStatusSpam EmailSendStatus = 3
|
|
||||||
EmailSendStatusFailed EmailSendStatus = 4
|
|
||||||
)
|
|
||||||
|
|
||||||
type DefaultEmail struct{}
|
type DefaultEmail struct{}
|
||||||
|
|
||||||
func (l *DefaultEmail) InitEmail(ctx context.Context, params EmailConfigData,logger loggerx.LoggerInterface) (Email, error) {
|
func (l *DefaultEmail) InitEmail(ctx context.Context, opt ...Option) (Email, error) {
|
||||||
return &DefaultEmail{}, errors.New("not implemented")
|
return &DefaultEmail{}, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DefaultEmail) Send(ctx context.Context, params Message) error {
|
func (l *DefaultEmail) Send(ctx context.Context, params Message) error {
|
||||||
return errors.New("not implemented")
|
return errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化一个接口
|
||||||
|
|
||||||
|
// 实际执行一个接口
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package interfaces
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/yuninks/loggerx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type emailOption struct {
|
||||||
|
logger loggerx.LoggerInterface
|
||||||
|
|
||||||
|
Smtp *EmailConfigDataSmtp `json:"smtp,omitempty"` // smtp
|
||||||
|
Aws *EmailConfigDataAws `json:"aws,omitempty"` // 亚马逊
|
||||||
|
Aliyun *EmialConfigDataAliyun `json:"aliyun,omitempty"` // 阿里云
|
||||||
|
Mailgun *EmialConfigDataMailgun `json:"mailgun,omitempty"` // mailgun
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultOptions() emailOption {
|
||||||
|
ctx := context.Background()
|
||||||
|
return emailOption{
|
||||||
|
logger: loggerx.NewLogger(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*emailOption)
|
||||||
|
|
||||||
|
// 设置日志
|
||||||
|
func SetLogger(logger loggerx.LoggerInterface) Option {
|
||||||
|
return func(o *emailOption) {
|
||||||
|
o.logger = logger
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user