增加按照模版发送邮件
This commit is contained in:
parent
bc8268c3f3
commit
350f631040
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,4 +17,5 @@
|
||||
# vendor/
|
||||
.idea
|
||||
.vscode
|
||||
*_test.go
|
||||
|
||||
|
126
mail/code_tpl.html
Normal file
126
mail/code_tpl.html
Normal file
@ -0,0 +1,126 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<base target="_blank" />
|
||||
<style type="text/css">
|
||||
::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<style id="cloudAttachStyle" type="text/css">
|
||||
#divNeteaseBigAttach,
|
||||
#divNeteaseBigAttach_bak {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<style id="blockquoteStyle" type="text/css">
|
||||
blockquote {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-size: 14px;
|
||||
font-family: arial, verdana, sans-serif;
|
||||
line-height: 1.666;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
overflow: auto;
|
||||
white-space: normal;
|
||||
word-wrap: break-word;
|
||||
min-height: 100px
|
||||
}
|
||||
|
||||
td,
|
||||
input,
|
||||
button,
|
||||
select,
|
||||
body {
|
||||
font-family: Helvetica, 'Microsoft Yahei', verdana
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
white-space: -moz-pre-wrap;
|
||||
white-space: -pre-wrap;
|
||||
white-space: -o-pre-wrap;
|
||||
word-wrap: break-word;
|
||||
width: 95%
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
font-family: arial, verdana, sans-serif;
|
||||
line-height: 1.666
|
||||
}
|
||||
|
||||
img {
|
||||
border: 0
|
||||
}
|
||||
|
||||
header,
|
||||
footer,
|
||||
section,
|
||||
aside,
|
||||
article,
|
||||
nav,
|
||||
hgroup,
|
||||
figure,
|
||||
figcaption {
|
||||
display: block
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin-right: 0px
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body tabindex="0" role="listitem">
|
||||
<table width="700" border="0" align="center" cellspacing="0" style="width:700px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<div style="width:700px;margin:0 auto;border-bottom:1px solid #ccc;margin-bottom:30px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="700" height="39"
|
||||
style="font:12px Tahoma, Arial, 宋体;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="210"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div style="width:680px;padding:0 10px;margin:0 auto;">
|
||||
<div style="line-height:1.5;font-size:14px;margin-bottom:25px;color:#4d4d4d;">
|
||||
<strong style="display:block;margin-bottom:15px;">尊敬的用户:<span
|
||||
style="color:#f60;font-size: 16px;"></span>您好!</strong>
|
||||
<strong style="display:block;margin-bottom:15px;">
|
||||
您正在进行<span style="color: red">{operate_description}</span>操作,请在验证码输入框中输入:<span
|
||||
style="color:#f60;font-size: 24px">{operate_code}</span>,以完成操作。
|
||||
</strong>
|
||||
</div>
|
||||
<div style="margin-bottom:30px;">
|
||||
<small style="display:block;margin-bottom:20px;font-size:12px;">
|
||||
<p style="color:#747474;">
|
||||
注意:此操作可能会修改您的密码、登录邮箱或绑定手机。如非本人操作,请及时登录并修改密码以保证帐户安全
|
||||
<br>(开发者不会向你索取此验证码,请勿泄漏!)
|
||||
</p>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div style="width:700px;margin:0 auto;">
|
||||
<div
|
||||
style="padding:10px 10px 0;border-top:1px solid #ccc;color:#747474;margin-bottom:20px;line-height:1.3em;font-size:12px;">
|
||||
<p>此为系统邮件,请勿回复<br>
|
||||
请保管好您的邮箱,避免账号被他人盗用
|
||||
</p>
|
||||
<p>白茶清欢的个人网站</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user