代码拉取完成,页面将自动刷新
// Copyright 2019 pandora Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pandora
import (
"strings"
"gopkg.in/gomail.v2"
)
type SendMail struct {
Enable int
Smtp string
Port int
User string
Pass string
dialer *gomail.Dialer
}
func NewSendMail(mail *SendMail) *SendMail {
mail.dialer = gomail.NewPlainDialer(mail.Smtp, mail.Port, mail.User, mail.Pass)
return mail
}
func (mail *SendMail) send(msg *SendMailMessage) error {
if mail.Enable == 0 {
return nil
}
msg.mail = mail
m := msg.NewMessage()
if err := mail.dialer.DialAndSend(m); err != nil {
return err
}
return nil
}
func (mail *SendMail) Send(msg *SendMailMessage) {
if err := mail.send(msg); err != nil {
App.Logger.Error(
"send mail failed, to[%s], cc[%s], subject[%s]",
strings.Join(msg.To, ","),
strings.Join(msg.Cc, ","),
msg.Subject,
)
}
}
func (mail *SendMail) AsyncSend(msg *SendMailMessage) {
go mail.Send(msg)
}
type SendMailMessage struct {
From string
To []string
Cc []string
Subject string
Body string
Attach string
mail *SendMail
}
func (m *SendMailMessage) NewMessage() *gomail.Message {
mailMsg := gomail.NewMessage()
if m.From == "" {
mailMsg.SetHeader("From", m.mail.User)
} else {
mailMsg.SetHeader("From", m.From)
}
mailMsg.SetHeader("To", m.To...)
if len(m.Cc) > 0 {
mailMsg.SetHeader("Cc", m.Cc...)
}
mailMsg.SetHeader("Subject", m.Subject)
mailMsg.SetBody("text/html", m.Body)
if m.Attach != "" {
mailMsg.Attach(m.Attach)
}
return mailMsg
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。