forked from mindoc-org/mindoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
51 lines (47 loc) · 961 Bytes
/
util.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
package mail
import (
"net/mail"
)
func MailAddr(name string, address string) *mail.Address {
return &mail.Address{
Name: name,
Address: address,
}
}
type Attachments struct {
Files []string
BaseDir string
}
//SendMail 发送电邮
func SendMail(subject string, content string, receiver, sender string,
bcc []string, smtpConfig *SMTPConfig, attachments *Attachments) error {
c := NewSMTPClient(smtpConfig)
m := NewMail()
err := m.AddTo(receiver) //receiver e.g. "Barry Gibbs <[email protected]>"
if err != nil {
return err
}
err = m.AddFrom(sender)
if err != nil {
return err
}
m.AddSubject(subject)
//m.AddText("Some text :)")
m.AddHTML(content)
if attachments != nil {
m.BaseDir = attachments.BaseDir
for _, v := range attachments.Files {
err = m.AddAttachment(v)
if err != nil {
return err
}
}
}
for _, addr := range bcc {
err = m.AddBCC(addr)
if err != nil {
return err
}
}
return c.Send(m)
}