diff --git a/.gitignore b/.gitignore index e2f1f53..a6b542a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ # vendor/ .idea .vscode +*_test.go diff --git a/mail/code_tpl.html b/mail/code_tpl.html new file mode 100644 index 0000000..91549d0 --- /dev/null +++ b/mail/code_tpl.html @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
+
+
+ 尊敬的用户:您好! + + 您正在进行{operate_description}操作,请在验证码输入框中输入:{operate_code},以完成操作。 + +
+
+ +

+ 注意:此操作可能会修改您的密码、登录邮箱或绑定手机。如非本人操作,请及时登录并修改密码以保证帐户安全 +
(开发者不会向你索取此验证码,请勿泄漏!) +

+
+
+
+
+
+

此为系统邮件,请勿回复
+ 请保管好您的邮箱,避免账号被他人盗用 +

+

白茶清欢的个人网站

+
+
+
+ + \ No newline at end of file diff --git a/mail/mail.go b/mail/mail.go index c5a9a33..dbfb614 100644 --- a/mail/mail.go +++ b/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) +}