Skip to content

Commit

Permalink
修复邮箱图片显示逻辑,兼容 google gmail
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Mar 22, 2024
1 parent eb7401f commit e5c6533
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ git clone https://github.com/bjdgyc/anylink.git


cd anylink
bash build_web.sh
bash build.sh

# 注意使用root权限运行
Expand Down
11 changes: 10 additions & 1 deletion server/admin/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/bjdgyc/anylink/dbdata"
"github.com/bjdgyc/anylink/sessdata"
"github.com/skip2/go-qrcode"
mail "github.com/xhit/go-simple-mail/v2"
)

func UserList(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -272,5 +273,13 @@ func userAccountMail(user *dbdata.User) error {
return err
}
// fmt.Println(w.String())
return SendMail(base.Cfg.Issuer+"平台通知", user.Email, w.String())
imgData, _ := userOtpQr(user.Id, false)
attach := &mail.File{
MimeType: "image/png",
Name: "userOtpQr.png",
Data: []byte(imgData),
Inline: true,
}

return SendMail(base.Cfg.Issuer, user.Email, w.String(), attach)
}
6 changes: 5 additions & 1 deletion server/admin/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func GetJwtData(jwtToken string) (map[string]interface{}, error) {
return claims, nil
}

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

dataSmtp := &dbdata.SettingSmtp{}
err := dbdata.SettingGet(dataSmtp)
Expand Down Expand Up @@ -102,6 +102,10 @@ func SendMail(subject, to, htmlBody string) error {
AddTo(to).
SetSubject(subject)

if attach != nil {
email.Attach(attach)
}

email.SetBody(mail.TextHTML, htmlBody)

// Call Send and pass the client
Expand Down
9 changes: 7 additions & 2 deletions server/dbdata/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,15 @@ const accountMail = `<p>您好:</p>
用户PIN码: <b>{{.PinCode}}</b> <br/>
<!--
用户动态码(3天后失效):<br/>
<img src="{{.OtpImg}}"/>
<img src="{{.OtpImg}}"/><br/>
用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/><br/>
下面是兼容 gmail 的写法
-->
用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/>
<img src="cid:userOtpQr.png" alt="userOtpQr" /><br/>
</p>
<div>
使用说明:
Expand Down

0 comments on commit e5c6533

Please sign in to comment.