2024-08-23 16:17:32 +08:00
|
|
|
package email
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"service/dbstruct"
|
|
|
|
"service/library/logger"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"gopkg.in/gomail.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SendRavenIQTestResult(mail *dbstruct.Email, address, password string) error {
|
|
|
|
|
|
|
|
url := mail.MediaComponent.Images[0].Urls[0]
|
|
|
|
body := &strings.Builder{}
|
|
|
|
h2 := fmt.Sprintf("<h2>%v</h2>", mail.GetText())
|
|
|
|
img := fmt.Sprintf("<img border=\"0\" src=\"%v\" alt=\"图片加载错误,请联系管理员\">", url)
|
|
|
|
body.WriteString(h2)
|
|
|
|
body.WriteString(img)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2024-08-23 16:39:19 +08:00
|
|
|
err := gomail.NewDialer("smtp.office365.com", 587, address, password).DialAndSend(m)
|
2024-08-23 16:17:32 +08:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("Send Email Fail", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|