Files
Message-Push-Nest/service/send_message_service/send_email.go
T

38 lines
1.0 KiB
Go
Raw Normal View History

2024-01-03 17:12:47 +08:00
package send_message_service
import (
"fmt"
"message-nest/models"
"message-nest/pkg/message"
"message-nest/service/send_ins_service"
"message-nest/service/send_way_service"
)
type EmailService struct {
}
// SendTaskEmail 执行发送邮件
2024-01-06 17:44:45 +08:00
func (s *EmailService) SendTaskEmail(auth send_way_service.WayDetailEmail, ins models.SendTasksIns, typeC string, title string, content string) string {
2024-01-03 17:12:47 +08:00
insService := send_ins_service.SendTaskInsService{}
errStr, c := insService.ValidateDiffIns(ins)
if errStr != "" {
return errStr
}
config, ok := c.(models.InsEmailConfig)
if !ok {
return "邮箱config校验失败"
}
var emailer message.EmailMessage
errMsg := ""
emailer.Init(auth.Server, auth.Port, auth.Account, auth.Passwd)
if typeC == "text" {
2024-01-06 17:44:45 +08:00
errMsg = emailer.SendTextMessage(config.ToAccount, title, content)
2024-01-03 17:12:47 +08:00
} else if typeC == "html" {
2024-01-06 17:44:45 +08:00
errMsg = emailer.SendHtmlMessage(config.ToAccount, title, content)
2024-01-03 17:12:47 +08:00
} else {
errMsg = fmt.Sprintf("未知的邮件发送内容类型:%s", ins.ContentType)
}
return errMsg
}