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 {
|
func NewAliyun() *Aliyun {
|
||||||
aliyun := &Aliyun{}
|
aliyun := &Aliyun{}
|
||||||
aliyun.Options = interfaces.DefaultOptions()
|
aliyun.Options = interfaces.DefaultOptions()
|
||||||
aliyun.EmailType = "Aliyun"
|
aliyun.EmailType = interfaces.EmailTypeAliyun
|
||||||
return aliyun
|
return aliyun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ type Aws struct {
|
|||||||
func NewAws() *Aws {
|
func NewAws() *Aws {
|
||||||
aws := &Aws{}
|
aws := &Aws{}
|
||||||
aws.Options = interfaces.DefaultOptions()
|
aws.Options = interfaces.DefaultOptions()
|
||||||
aws.EmailType = "Aws"
|
aws.EmailType = interfaces.EmailTypeAws
|
||||||
return aws
|
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
|
package interfaces
|
||||||
|
|
||||||
|
|
||||||
|
type EmailType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
EmailTypeAliyun EmailType = "aliyun"
|
||||||
|
EmailTypeAws EmailType = "aws"
|
||||||
|
EmailTypeMailgun EmailType = "mailgun"
|
||||||
|
EmailTypeSmtp EmailType = "smtp"
|
||||||
|
)
|
||||||
|
|
||||||
type EmialConfigDataMailgun struct {
|
type EmialConfigDataMailgun struct {
|
||||||
ApiKey string `json:"api_key"` // mailgun api key
|
ApiKey string `json:"api_key"` // mailgun api key
|
||||||
Domain string `json:"domain"` // mailgun domain
|
Domain string `json:"domain"` // mailgun domain
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EmailType string
|
|
||||||
|
|
||||||
type EmailInterface interface {
|
type EmailInterface interface {
|
||||||
SetOption(ctx context.Context, opt ...Option) (EmailInterface, error) // 初始化
|
SetOption(ctx context.Context, opt ...Option) (EmailInterface, error) // 初始化
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ type MailGun struct {
|
|||||||
func NewMailGun() *MailGun {
|
func NewMailGun() *MailGun {
|
||||||
mailgun := &MailGun{}
|
mailgun := &MailGun{}
|
||||||
mailgun.Options = interfaces.DefaultOptions()
|
mailgun.Options = interfaces.DefaultOptions()
|
||||||
mailgun.EmailType = "MailGun"
|
mailgun.EmailType = interfaces.EmailTypeMailgun
|
||||||
return mailgun
|
return mailgun
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,22 +8,22 @@ import (
|
|||||||
"code.yun.ink/pkg/mailx/smtp"
|
"code.yun.ink/pkg/mailx/smtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var platform *interfaces.DefaultEmailFactory
|
var Platform interfaces.EmailFactoryInterface
|
||||||
|
|
||||||
// 注册
|
// 注册
|
||||||
func init() {
|
func init() {
|
||||||
platform = interfaces.NewDefaultEmailFactory()
|
Platform = interfaces.NewDefaultEmailFactory()
|
||||||
|
|
||||||
// 阿里
|
// 阿里
|
||||||
platform.Register(aliyun.NewAliyun())
|
Platform.Register(aliyun.NewAliyun())
|
||||||
|
|
||||||
// AWS
|
// AWS
|
||||||
platform.Register(aws.NewAws())
|
Platform.Register(aws.NewAws())
|
||||||
|
|
||||||
// Smtp
|
// Smtp
|
||||||
platform.Register(smtp.NewSmtp())
|
Platform.Register(smtp.NewSmtp())
|
||||||
|
|
||||||
// mailgun
|
// mailgun
|
||||||
platform.Register(mailgun.NewMailGun())
|
Platform.Register(mailgun.NewMailGun())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ type Smtp struct {
|
|||||||
func NewSmtp() *Smtp {
|
func NewSmtp() *Smtp {
|
||||||
smtp := &Smtp{}
|
smtp := &Smtp{}
|
||||||
smtp.Options = interfaces.DefaultOptions()
|
smtp.Options = interfaces.DefaultOptions()
|
||||||
smtp.EmailType = "Smtp"
|
smtp.EmailType = interfaces.EmailTypeSmtp
|
||||||
return smtp
|
return smtp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user