by Robin at 20240823 #707

Merged
chenhao merged 1 commits from feat-IRONFANS-210-Robin into test 2024-08-23 16:54:03 +08:00
1 changed files with 17 additions and 2 deletions
Showing only changes of commit 95e83bafe2 - Show all commits

View File

@ -2,6 +2,8 @@ package email
import (
"fmt"
"io"
"net/http"
"service/dbstruct"
"service/library/logger"
"strings"
@ -18,15 +20,28 @@ func SendRavenIQTestResult(mail *dbstruct.Email, address, password string) error
body.WriteString(h2)
body.WriteString(img)
response, err := http.Get(url)
if err != nil {
return err
}
attach, err := io.ReadAll(response.Body)
response.Body.Close()
if err != nil {
return err
}
m := gomail.NewMessage()
m.SetHeader("From", mail.GetFrom())
m.SetHeader("To", mail.GetTo())
m.SetHeader("Subject", mail.GetSubject())
m.SetBody("text/html", body.String())
m.Attach(url)
m.Attach("测评结果", gomail.SetCopyFunc(func(w io.Writer) error { //设置邮件附件 第一个参数是附件名称 第二个参数是二进制文件流
_, err := w.Write(attach)
return err
}))
err := gomail.NewDialer("smtp.office365.com", 587, address, password).DialAndSend(m)
err = gomail.NewDialer("smtp.office365.com", 587, address, password).DialAndSend(m)
if err != nil {
logger.Error("Send Email Fail", err)
return err