From 350f631040d0d349527edbf8d49f9921d73175b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 Aug 2021 13:33:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E7=85=A7=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + mail/code_tpl.html | 126 +++++++++++++++++++++++++++++++++++++++++++++ mail/mail.go | 23 +++++++++ 3 files changed, 150 insertions(+) create mode 100644 mail/code_tpl.html 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) +}