You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1004 B
39 lines
1004 B
package email |
|
|
|
import ( |
|
"os" |
|
|
|
"go-common/app/admin/main/up/conf" |
|
"go-common/library/log" |
|
|
|
"gopkg.in/gomail.v2" |
|
) |
|
|
|
//SendMail send the email. |
|
func (d *Dao) SendMail(body string, subject string, send ...string) (err error) { |
|
msg := gomail.NewMessage() |
|
msg.SetHeader("From", conf.Conf.MailConf.Username) |
|
msg.SetHeader("To", send...) |
|
msg.SetHeader("Subject", subject) |
|
msg.SetBody("text/html", body, gomail.SetPartEncoding(gomail.Base64)) |
|
if err = d.email.DialAndSend(msg); err != nil { |
|
log.Error("s.email.DialAndSend error(%v)", err) |
|
return |
|
} |
|
return |
|
} |
|
|
|
//SendMailAttach send the email. |
|
func (d *Dao) SendMailAttach(filename string, subject string, send []string) (err error) { |
|
msg := gomail.NewMessage() |
|
msg.SetHeader("From", conf.Conf.MailConf.Username) |
|
msg.SetHeader("To", send...) |
|
msg.SetHeader("Subject", subject) |
|
msg.Attach(filename) |
|
if err = d.email.DialAndSend(msg); err != nil { |
|
log.Error("s.email.DialAndSend error(%v)", err) |
|
return |
|
} |
|
err = os.Remove(filename) |
|
return |
|
}
|
|
|