前端之家收集整理的这篇文章主要介绍了
golang项目邮件发送模块代码分享,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package sendMail
import (
"fmt"
"net/smtp"
"strings"
)
type senderInfo struct {
User string `jsob:user`
Passwd string `json:passwd`
Host_port string `json:host_port`
Mailaddr string `json:mailaddr`
Subject string `json:subject`
}
func (self *senderInfo) SendMail(toList,body string) error {
head := fmt.Sprintf("To: %v\r\nSubject: %v\r\nContent-Type: text/plain;charset=UTF-8\r\n\r\n",toList,self.Subject)
host := strings.Split(self.Host_port,":")
if len(host) != 2 {
return fmt.Errorf("%v not a valid host_port",self.Host_port)
}
auth := smtp.PlainAuth("",self.User,self.Passwd,host[0])
return smtp.SendMail(self.Host_port,auth,self.Mailaddr,strings.Split(toList,";"),[]byte(head+body))
}
原文链接:https://www.f2er.com/go/189875.html