提交 v1.3.0 beta
This commit is contained in:
@ -4,36 +4,39 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/smtp"
|
||||
"next-terminal/server/common/nt"
|
||||
|
||||
"next-terminal/server/constant"
|
||||
"next-terminal/server/branding"
|
||||
"next-terminal/server/log"
|
||||
"next-terminal/server/repository"
|
||||
|
||||
"github.com/jordan-wright/email"
|
||||
)
|
||||
|
||||
var MailService = new(mailService)
|
||||
|
||||
type mailService struct {
|
||||
}
|
||||
|
||||
func (r mailService) SendMail(to, subject, text string) {
|
||||
propertiesMap := repository.PropertyRepository.FindAllMap(context.TODO())
|
||||
host := propertiesMap[constant.MailHost]
|
||||
port := propertiesMap[constant.MailPort]
|
||||
username := propertiesMap[constant.MailUsername]
|
||||
password := propertiesMap[constant.MailPassword]
|
||||
host := propertiesMap[nt.MailHost]
|
||||
port := propertiesMap[nt.MailPort]
|
||||
username := propertiesMap[nt.MailUsername]
|
||||
password := propertiesMap[nt.MailPassword]
|
||||
|
||||
if host == "" || port == "" || username == "" || password == "" {
|
||||
log.Debugf("邮箱信息不完整,跳过发送邮件。")
|
||||
log.Warn("邮箱信息不完整,跳过发送邮件。")
|
||||
return
|
||||
}
|
||||
|
||||
e := email.NewEmail()
|
||||
e.From = fmt.Sprintf("%s <%s>", constant.AppName, username)
|
||||
e.From = fmt.Sprintf("%s <%s>", branding.Name, username)
|
||||
e.To = []string{to}
|
||||
e.Subject = subject
|
||||
e.Text = []byte(text)
|
||||
err := e.Send(host+":"+port, smtp.PlainAuth("", username, password, host))
|
||||
if err != nil {
|
||||
log.Errorf("邮件发送失败: %v", err.Error())
|
||||
log.Error("邮件发送失败", log.String("err", err.Error()))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user