Du kannst nicht mehr als 25 Themen auswählen
Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
34 Zeilen
761 B
34 Zeilen
761 B
vor 4 Jahren
|
package service
|
||
|
|
||
|
import (
|
||
|
"../conf"
|
||
|
"gopkg.in/gomail.v2"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type Email struct {
|
||
|
host string
|
||
|
port string
|
||
|
user string
|
||
|
pass string
|
||
|
}
|
||
|
|
||
|
func NerEmail(conf *conf.Config) *Email {
|
||
|
host:=conf.Read("smtp","email_host")
|
||
|
port:=conf.Read("smtp","port")
|
||
|
user:=conf.Read("smtp","email_user")
|
||
|
pass:=conf.Read("smtp","email_pwd")
|
||
|
return &Email{host: host,port: port,user: user,pass: pass}
|
||
|
}
|
||
|
|
||
|
func (this *Email) SendMail(mailTo []string,subject,body string) error {
|
||
|
port, _ := strconv.Atoi(this.port)
|
||
|
m:=gomail.NewMessage()
|
||
|
m.SetHeader("From", "<" + this.user + ">")
|
||
|
m.SetHeader("To", mailTo...)
|
||
|
m.SetHeader("Subject",subject)
|
||
|
m.SetBody("text/html",body)
|
||
|
d := gomail.NewDialer(this.host,port,this.user,this.pass)
|
||
|
err:=d.DialAndSend(m)
|
||
|
return err
|
||
|
}
|