12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package notify
- import (
- "crypto/tls"
- "gopkg.in/gomail.v2"
- "iot_manager_service/config"
- "strconv"
- )
- func SendEmail(html string, title string, receiver ...string) error {
- message := html
- config := config.Instance().MonitNotice.Email
-
-
-
-
- host := config.Host
- port := config.Port
- userName := config.UserName
- password := config.PassWord
- m := gomail.NewMessage()
- m.SetHeader("From", userName)
-
- m.SetHeader("To", receiver...)
-
-
- m.SetHeader("Subject", title)
-
-
-
- m.SetBody("text/html", message)
-
-
-
-
-
- portInt, _ := strconv.Atoi(port)
- d := gomail.NewDialer(
- host,
- portInt,
- userName,
- password,
- )
-
- d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
- if err := d.DialAndSend(m); err != nil {
- return err
- }
- return nil
- }
|