调整mail实例
This commit is contained in:
parent
ad91ec88c7
commit
90bc05e1d0
43
mail/mail.go
43
mail/mail.go
@ -14,12 +14,7 @@ import (
|
|||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
type Mail struct {
|
||||||
// Mail 邮件服务实例
|
|
||||||
Mail *mail
|
|
||||||
)
|
|
||||||
|
|
||||||
type mail struct {
|
|
||||||
conf map[string]string
|
conf map[string]string
|
||||||
port int
|
port int
|
||||||
mailDialer *gomail.Dialer
|
mailDialer *gomail.Dialer
|
||||||
@ -30,24 +25,22 @@ type mail struct {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:32 上午 2021/8/13
|
// Date : 1:32 上午 2021/8/13
|
||||||
func NewMailMessage(fromMail string, fromMailName string, pass string, host string, port int) *mail {
|
func NewMailMessage(fromMail string, fromMailName string, pass string, host string, port int) *Mail {
|
||||||
if Mail == nil {
|
m := &Mail{}
|
||||||
Mail = &mail{}
|
if len(fromMailName) == 0 {
|
||||||
if len(fromMailName) == 0 {
|
fromMailName = "系统邮件"
|
||||||
fromMailName = "系统邮件"
|
|
||||||
}
|
|
||||||
Mail.conf = map[string]string{
|
|
||||||
"user": fromMail,
|
|
||||||
"pass": pass,
|
|
||||||
"host": host,
|
|
||||||
"port": fmt.Sprintf("%v", port),
|
|
||||||
"from_mail_name": fromMailName,
|
|
||||||
}
|
|
||||||
|
|
||||||
Mail.port = port
|
|
||||||
Mail.mailDialer = gomail.NewDialer(Mail.conf["host"], port, Mail.conf["user"], Mail.conf["pass"])
|
|
||||||
}
|
}
|
||||||
return Mail
|
m.conf = map[string]string{
|
||||||
|
"user": fromMail,
|
||||||
|
"pass": pass,
|
||||||
|
"host": host,
|
||||||
|
"port": fmt.Sprintf("%v", port),
|
||||||
|
"from_mail_name": fromMailName,
|
||||||
|
}
|
||||||
|
|
||||||
|
m.port = port
|
||||||
|
m.mailDialer = gomail.NewDialer(m.conf["host"], port, m.conf["user"], m.conf["pass"])
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseSend 基础邮件发送
|
// BaseSend 基础邮件发送
|
||||||
@ -55,7 +48,7 @@ func NewMailMessage(fromMail string, fromMailName string, pass string, host stri
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:14 上午 2021/8/13
|
// Date : 1:14 上午 2021/8/13
|
||||||
func (m *mail) BaseSend(mailTo []string, subject string, body string) error {
|
func (m *Mail) BaseSend(mailTo []string, subject string, body string) error {
|
||||||
message := gomail.NewMessage()
|
message := gomail.NewMessage()
|
||||||
message.SetHeader("From", message.FormatAddress(m.conf["user"], m.conf["from_mail_name"])) //这种方式可以添加别名,即“XX官方”
|
message.SetHeader("From", message.FormatAddress(m.conf["user"], m.conf["from_mail_name"])) //这种方式可以添加别名,即“XX官方”
|
||||||
//说明:如果是用网易邮箱账号发送,以下方法别名可以是中文,如果是qq企业邮箱,以下方法用中文别名,会报错,需要用上面此方法转码
|
//说明:如果是用网易邮箱账号发送,以下方法别名可以是中文,如果是qq企业邮箱,以下方法用中文别名,会报错,需要用上面此方法转码
|
||||||
@ -75,7 +68,7 @@ func (m *mail) BaseSend(mailTo []string, subject string, body string) error {
|
|||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
//
|
//
|
||||||
// Date : 1:05 下午 2021/8/14
|
// Date : 1:05 下午 2021/8/14
|
||||||
func (m *mail) TplSend(mailTo []string, subject string, tpl string, bindData map[string]string) error {
|
func (m *Mail) TplSend(mailTo []string, subject string, tpl string, bindData map[string]string) error {
|
||||||
var (
|
var (
|
||||||
tplContent []byte
|
tplContent []byte
|
||||||
err error
|
err error
|
||||||
|
Loading…
Reference in New Issue
Block a user