增加按照模版发送邮件
This commit is contained in:
23
mail/mail.go
23
mail/mail.go
@ -7,6 +7,9 @@ package mail
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/gopkg/util"
|
||||
|
||||
"gopkg.in/gomail.v2"
|
||||
)
|
||||
@ -66,3 +69,23 @@ func (m *mail) BaseSend(mailTo []string, subject string, body string) error {
|
||||
|
||||
return d.DialAndSend(message)
|
||||
}
|
||||
|
||||
// TplSend 使用模版发送邮件
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 1:05 下午 2021/8/14
|
||||
func (m *mail) TplSend(mailTo []string, subject string, tpl string, bindData map[string]string) error {
|
||||
var (
|
||||
tplContent []byte
|
||||
err error
|
||||
)
|
||||
if tplContent, err = util.ReadFileContent(tpl); nil != err {
|
||||
return err
|
||||
}
|
||||
mailBody := string(tplContent)
|
||||
for k, v := range bindData {
|
||||
mailBody = strings.ReplaceAll(mailBody, "{"+k+"}", v)
|
||||
}
|
||||
return m.BaseSend(mailTo, subject, mailBody)
|
||||
}
|
||||
|
Reference in New Issue
Block a user