-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.go
64 lines (52 loc) · 1 KB
/
mail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package mail
import (
"github.com/hopeio/cherry/utils/log"
"net/smtp"
"strings"
)
type Config struct {
AuthType string `comment:"CRAMMD5Auth,PLAINAuth"`
PlainAuth PlainAuth
CRAMMD5Auth CRAMMD5Auth
}
type PlainAuth struct {
Identity string
Host string
Port string
From string
Password string
}
type CRAMMD5Auth struct {
UserName string
Secret string
}
func (c *Config) InitBeforeInject() {
}
func (c *Config) Init() {
}
func (c *Config) Build() smtp.Auth {
c.Init()
if strings.ToUpper(c.AuthType) == "PLAINAUTH" {
pc := c.PlainAuth
return smtp.PlainAuth(pc.Identity, pc.From, pc.Password, pc.Host)
}
if strings.ToUpper(c.AuthType) == "CRAMMD5AUTH" {
cc := c.CRAMMD5Auth
return smtp.CRAMMD5Auth(cc.UserName, cc.Secret)
}
log.Fatal("邮箱配置AuthType必填")
return nil
}
type Mail struct {
smtp.Auth
Conf Config
}
func (m *Mail) Config() any {
return &m.Conf
}
func (m *Mail) SetEntity() {
m.Auth = m.Conf.Build()
}
func (m *Mail) Close() error {
return nil
}