增加按照模版发送邮件

This commit is contained in:
2021-08-14 13:33:29 +08:00
parent bc8268c3f3
commit 350f631040
3 changed files with 150 additions and 0 deletions

View File

@ -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)
}