feat: add message push function call

This commit is contained in:
engigu
2026-03-04 21:45:43 +08:00
parent d4663cb492
commit 81b8d2a93d
53 changed files with 4161 additions and 33 deletions
+46
View File
@@ -0,0 +1,46 @@
package message
import (
"fmt"
"gopkg.in/gomail.v2"
)
type EmailMessage struct {
Server string
Port int
Account string
Passwd string
FromName string
GM *gomail.Dialer
}
func (e *EmailMessage) Init(host string, port int, account string, passwd string, fromName string) {
e.Server = host
e.Port = port
e.Account = account
e.Passwd = passwd
e.FromName = fromName
e.GM = gomail.NewDialer(host, port, account, passwd)
}
func (e *EmailMessage) SendTextMessage(toEmail string, title string, content string) string {
m := gomail.NewMessage()
if e.FromName != "" {
m.SetAddressHeader("From", e.Account, e.FromName)
} else {
m.SetHeader("From", e.Account)
}
m.SetHeader("To", toEmail)
m.SetHeader("Subject", title)
m.SetBody("text/html", content)
if err := e.GM.DialAndSend(m); err != nil {
return fmt.Sprintf("邮件发送失败: %s", err)
}
return ""
}
func (e *EmailMessage) SendHtmlMessage(toEmail string, title string, content string) string {
return e.SendTextMessage(toEmail, title, content)
}