Skip to content

Commit e5c6533

Browse files
committed
修复邮箱图片显示逻辑,兼容 google gmail
1 parent eb7401f commit e5c6533

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ git clone https://github.com/bjdgyc/anylink.git
8686

8787

8888
cd anylink
89+
bash build_web.sh
8990
bash build.sh
9091

9192
# 注意使用root权限运行

server/admin/api_user.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/bjdgyc/anylink/dbdata"
1818
"github.com/bjdgyc/anylink/sessdata"
1919
"github.com/skip2/go-qrcode"
20+
mail "github.com/xhit/go-simple-mail/v2"
2021
)
2122

2223
func UserList(w http.ResponseWriter, r *http.Request) {
@@ -272,5 +273,13 @@ func userAccountMail(user *dbdata.User) error {
272273
return err
273274
}
274275
// fmt.Println(w.String())
275-
return SendMail(base.Cfg.Issuer+"平台通知", user.Email, w.String())
276+
imgData, _ := userOtpQr(user.Id, false)
277+
attach := &mail.File{
278+
MimeType: "image/png",
279+
Name: "userOtpQr.png",
280+
Data: []byte(imgData),
281+
Inline: true,
282+
}
283+
284+
return SendMail(base.Cfg.Issuer, user.Email, w.String(), attach)
276285
}

server/admin/common.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func GetJwtData(jwtToken string) (map[string]interface{}, error) {
4343
return claims, nil
4444
}
4545

46-
func SendMail(subject, to, htmlBody string) error {
46+
func SendMail(subject, to, htmlBody string, attach *mail.File) error {
4747

4848
dataSmtp := &dbdata.SettingSmtp{}
4949
err := dbdata.SettingGet(dataSmtp)
@@ -102,6 +102,10 @@ func SendMail(subject, to, htmlBody string) error {
102102
AddTo(to).
103103
SetSubject(subject)
104104

105+
if attach != nil {
106+
email.Attach(attach)
107+
}
108+
105109
email.SetBody(mail.TextHTML, htmlBody)
106110

107111
// Call Send and pass the client

server/dbdata/db.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,15 @@ const accountMail = `<p>您好:</p>
183183
用户PIN码: <b>{{.PinCode}}</b> <br/>
184184
<!--
185185
用户动态码(3天后失效):<br/>
186-
<img src="{{.OtpImg}}"/>
186+
<img src="{{.OtpImg}}"/><br/>
187+
188+
用户动态码(请妥善保存):<br/>
189+
<img src="{{.OtpImgBase64}}"/><br/>
190+
191+
下面是兼容 gmail 的写法
187192
-->
188193
用户动态码(请妥善保存):<br/>
189-
<img src="{{.OtpImgBase64}}"/>
194+
<img src="cid:userOtpQr.png" alt="userOtpQr" /><br/>
190195
</p>
191196
<div>
192197
使用说明:

0 commit comments

Comments
 (0)