修复邮箱图片显示逻辑,兼容 google gmail

This commit is contained in:
bjdgyc 2024-03-22 16:45:11 +08:00
parent eb7401f6e5
commit e5c6533c9b
4 changed files with 23 additions and 4 deletions

View File

@ -86,6 +86,7 @@ git clone https://github.com/bjdgyc/anylink.git
cd anylink cd anylink
bash build_web.sh
bash build.sh bash build.sh
# 注意使用root权限运行 # 注意使用root权限运行

View File

@ -17,6 +17,7 @@ import (
"github.com/bjdgyc/anylink/dbdata" "github.com/bjdgyc/anylink/dbdata"
"github.com/bjdgyc/anylink/sessdata" "github.com/bjdgyc/anylink/sessdata"
"github.com/skip2/go-qrcode" "github.com/skip2/go-qrcode"
mail "github.com/xhit/go-simple-mail/v2"
) )
func UserList(w http.ResponseWriter, r *http.Request) { func UserList(w http.ResponseWriter, r *http.Request) {
@ -272,5 +273,13 @@ func userAccountMail(user *dbdata.User) error {
return err return err
} }
// fmt.Println(w.String()) // 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)
} }

View File

@ -43,7 +43,7 @@ func GetJwtData(jwtToken string) (map[string]interface{}, error) {
return claims, nil return claims, nil
} }
func SendMail(subject, to, htmlBody string) error { func SendMail(subject, to, htmlBody string, attach *mail.File) error {
dataSmtp := &dbdata.SettingSmtp{} dataSmtp := &dbdata.SettingSmtp{}
err := dbdata.SettingGet(dataSmtp) err := dbdata.SettingGet(dataSmtp)
@ -102,6 +102,10 @@ func SendMail(subject, to, htmlBody string) error {
AddTo(to). AddTo(to).
SetSubject(subject) SetSubject(subject)
if attach != nil {
email.Attach(attach)
}
email.SetBody(mail.TextHTML, htmlBody) email.SetBody(mail.TextHTML, htmlBody)
// Call Send and pass the client // Call Send and pass the client

View File

@ -183,10 +183,15 @@ const accountMail = `<p>您好:</p>
用户PIN码: <b>{{.PinCode}}</b> <br/> 用户PIN码: <b>{{.PinCode}}</b> <br/>
<!-- <!--
用户动态码(3天后失效):<br/> 用户动态码(3天后失效):<br/>
<img src="{{.OtpImg}}"/> <img src="{{.OtpImg}}"/><br/>
用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/><br/>
下面是兼容 gmail 的写法
--> -->
用户动态码(请妥善保存):<br/> 用户动态码(请妥善保存):<br/>
<img src="{{.OtpImgBase64}}"/> <img src="cid:userOtpQr.png" alt="userOtpQr" /><br/>
</p> </p>
<div> <div>
使用说明: 使用说明: