解决公网邮箱发送失败问题
上一步中,我没有使用Mailhog
搭建自己的本地邮件服务器,而是直接使用腾讯企业邮箱服务器来发送邮件的,但是一直发送失败,后来发现是因为tls
问题,从github.com/jordan-wright/email
这个包中的issue
中看到了解决方法。
就是将Send
方法替换成SendWithTls
方法:
// Send 实现 send 方法
func (s *SMTP) Send(email Email, config map[string]string) bool {
e := emailPKG.NewEmail()
e.From = fmt.Sprintf("%v <%v>", email.From.Name, email.From.Address)
e.Bcc = email.Bcc
e.Cc = email.Cc
e.To = email.To
e.Subject = email.Subject
e.Text = email.Text
e.HTML = email.HTML
logger.DebugJSON("send email", "发送详情", e)
err := e.SendWithTLS(
fmt.Sprintf("%v:%v", config["host"], config["port"]),
smtp.PlainAuth(
"",
config["username"],
config["password"],
config["host"],
),
&tls.Config{
ServerName: config["host"],
},
)
if err != nil {
logger.ErrorString("send email", "发送失败", err.Error())
return false
}
logger.DebugString("send email", "发送成功", "")
return true
}
本帖已被设为精华帖!
本帖由系统于 1年前 自动加精
Veify写错了,是Verify