12345678910111213141516171819202122232425262728 |
- package notice
-
- import (
- "net/smtp"
- "strings"
- "git.links123.net/links123.com/monitor_status/config"
- )
-
- func SendEmailBySMTP(subject, email, content string, html bool) error {
- user := config.C.Notice.SMTP.User
- host := config.C.Notice.SMTP.Host
- port := config.C.Notice.SMTP.Port
- pass := config.C.Notice.SMTP.Password
-
- auth := smtp.PlainAuth("", user, pass, host)
-
- contentType := "Content-Type:text/plain;charset=UTF-8"
- if html {
- contentType = "Content-Type:text/html;charset=UTF-8"
- }
-
- msg := []byte("To: " + email + "\r\nFrom: " + user + ">\r\nSubject: " + subject + "\r\n" + contentType + "\r\n\r\n" + content)
-
- to := strings.Split(email, ";")
-
- return smtp.SendMail(strings.Join([]string{host, port}, ":"), auth, user, to, msg)
- }
|