ai-gateway/common/email.go

21 lines
552 B
Go
Raw Normal View History

2023-04-22 12:39:27 +00:00
package common
import (
"fmt"
"net/smtp"
"strings"
)
2023-04-22 12:39:27 +00:00
func SendEmail(subject string, receiver string, content string) error {
mail := []byte(fmt.Sprintf("To: %s\r\n"+
"From: %s<%s>\r\n"+
"Subject: %s\r\n"+
"Content-Type: text/html; charset=UTF-8\r\n\r\n%s\r\n",
receiver, SystemName, SMTPAccount, subject, content))
auth := smtp.PlainAuth("", SMTPAccount, SMTPToken, SMTPServer)
addr := fmt.Sprintf("%s:%d", SMTPServer, SMTPPort)
to := strings.Split(receiver, ";")
err := smtp.SendMail(addr, auth, SMTPAccount, to, mail)
2023-04-22 12:39:27 +00:00
return err
}