mirror of
https://gitee.com/sjqzhang/go-fastdfs.git
synced 2024-12-03 11:47:36 +08:00
31 lines
824 B
Go
31 lines
824 B
Go
package server
|
|
|
|
import (
|
|
"net/smtp"
|
|
"strings"
|
|
)
|
|
|
|
type Mail struct {
|
|
User string `json:"user"`
|
|
Password string `json:"password"`
|
|
Host string `json:"host"`
|
|
}
|
|
|
|
func (c *Server) SendToMail(to, subject, body, mailtype string) error {
|
|
host := Config().Mail.Host
|
|
user := Config().Mail.User
|
|
password := Config().Mail.Password
|
|
hp := strings.Split(host, ":")
|
|
auth := smtp.PlainAuth("", user, password, hp[0])
|
|
var contentType string
|
|
if mailtype == "html" {
|
|
contentType = "Content-Type: text/" + mailtype + "; charset=UTF-8"
|
|
} else {
|
|
contentType = "Content-Type: text/plain" + "; charset=UTF-8"
|
|
}
|
|
msg := []byte("To: " + to + "\r\nFrom: " + user + ">\r\nSubject: " + "\r\n" + contentType + "\r\n\r\n" + body)
|
|
sendTo := strings.Split(to, ";")
|
|
err := smtp.SendMail(host, auth, user, sendTo, msg)
|
|
return err
|
|
}
|