Merge remote-tracking branch 'origin/master' into dev
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ type Aliyun struct {
|
||||
func NewAliyun() *Aliyun {
|
||||
aliyun := &Aliyun{}
|
||||
aliyun.Options = interfaces.DefaultOptions()
|
||||
aliyun.EmailType = "Aliyun"
|
||||
aliyun.EmailType = interfaces.EmailTypeAliyun
|
||||
return aliyun
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ type Aws struct {
|
||||
func NewAws() *Aws {
|
||||
aws := &Aws{}
|
||||
aws.Options = interfaces.DefaultOptions()
|
||||
aws.EmailType = "Aws"
|
||||
aws.EmailType = interfaces.EmailTypeAws
|
||||
return aws
|
||||
}
|
||||
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.yun.ink/pkg/mailx"
|
||||
"code.yun.ink/pkg/mailx/interfaces"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
ch := mailx.Platform
|
||||
|
||||
em, err := ch.GetEmail(interfaces.EmailTypeSmtp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// 使用em进行后续操作
|
||||
em,err = em.SetOption(ctx, interfaces.SetSmtp(&interfaces.EmailConfigDataSmtp{
|
||||
Username: "support@email.blueoceanpay.com",
|
||||
Password: "SupporT2017",
|
||||
ReplyTo: "",
|
||||
Host: "smtpdm-ap-southeast-1.aliyun.com",
|
||||
Port: "80",
|
||||
}))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = em.Send(ctx, interfaces.Message{
|
||||
Form: "yun@blueoceanpay.com",
|
||||
To: []string{"995116474@qq.com"},
|
||||
Subject: "Test Email",
|
||||
Body: "Hello, this is a test email.",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package mailx
|
||||
|
||||
type Platform3rdType string
|
||||
|
||||
const (
|
||||
Platform3rdTypeAliyun Platform3rdType = "aliyun"
|
||||
Platform3rdTypeAws Platform3rdType = "aws"
|
||||
Platform3rdTypeMailgun Platform3rdType = "mailgun"
|
||||
Platform3rdTypeSmtp Platform3rdType = "smtp"
|
||||
)
|
||||
@@ -1,5 +1,15 @@
|
||||
package interfaces
|
||||
|
||||
|
||||
type EmailType string
|
||||
|
||||
const (
|
||||
EmailTypeAliyun EmailType = "aliyun"
|
||||
EmailTypeAws EmailType = "aws"
|
||||
EmailTypeMailgun EmailType = "mailgun"
|
||||
EmailTypeSmtp EmailType = "smtp"
|
||||
)
|
||||
|
||||
type EmialConfigDataMailgun struct {
|
||||
ApiKey string `json:"api_key"` // mailgun api key
|
||||
Domain string `json:"domain"` // mailgun domain
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type EmailType string
|
||||
|
||||
|
||||
type EmailInterface interface {
|
||||
SetOption(ctx context.Context, opt ...Option) (EmailInterface, error) // 初始化
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ type MailGun struct {
|
||||
func NewMailGun() *MailGun {
|
||||
mailgun := &MailGun{}
|
||||
mailgun.Options = interfaces.DefaultOptions()
|
||||
mailgun.EmailType = "MailGun"
|
||||
mailgun.EmailType = interfaces.EmailTypeMailgun
|
||||
return mailgun
|
||||
}
|
||||
|
||||
|
||||
@@ -8,22 +8,22 @@ import (
|
||||
"code.yun.ink/pkg/mailx/smtp"
|
||||
)
|
||||
|
||||
var platform *interfaces.DefaultEmailFactory
|
||||
var Platform interfaces.EmailFactoryInterface
|
||||
|
||||
// 注册
|
||||
func init() {
|
||||
platform = interfaces.NewDefaultEmailFactory()
|
||||
Platform = interfaces.NewDefaultEmailFactory()
|
||||
|
||||
// 阿里
|
||||
platform.Register(aliyun.NewAliyun())
|
||||
Platform.Register(aliyun.NewAliyun())
|
||||
|
||||
// AWS
|
||||
platform.Register(aws.NewAws())
|
||||
Platform.Register(aws.NewAws())
|
||||
|
||||
// Smtp
|
||||
platform.Register(smtp.NewSmtp())
|
||||
Platform.Register(smtp.NewSmtp())
|
||||
|
||||
// mailgun
|
||||
platform.Register(mailgun.NewMailGun())
|
||||
Platform.Register(mailgun.NewMailGun())
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ type Smtp struct {
|
||||
func NewSmtp() *Smtp {
|
||||
smtp := &Smtp{}
|
||||
smtp.Options = interfaces.DefaultOptions()
|
||||
smtp.EmailType = "Smtp"
|
||||
smtp.EmailType = interfaces.EmailTypeSmtp
|
||||
return smtp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user