加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

golang(beego) 发送邮件

发布时间:2020-12-16 18:48:34 所属栏目:大数据 来源:网络整理
导读:import ("net/smtp""strings")//发送邮件帮助类func SendMail(user,password,host,to,subject,body,mailtype string) error {hp := strings.Split(host,":")auth := smtp.PlainAuth("",user,hp[0])var content_type stringif mailtype == "html" {content_ty
import (
	"net/smtp"
	"strings"
)


//发送邮件帮助类
func SendMail(user,password,host,to,subject,body,mailtype string) error {
	hp := strings.Split(host,":")
	auth := smtp.PlainAuth("",user,hp[0])
	var content_type string
	if mailtype == "html" {
		content_type = "Content-Type: text/" + mailtype + "; charset=UTF-8"
	} else {
		content_type = "Content-Type: text/plain" + "; charset=UTF-8"
	}
	msg := []byte("To: " + to + "rnFrom: " + user + "<" + user + ">rnSubject: " + subject + "rn" + content_type + "rnrn" + body)
	send_to := strings.Split(to,";")
	err := smtp.SendMail(host,auth,send_to,msg)
	return err
}


用法:


err := SendMail("发送的邮箱","发送的邮箱密码","smtp.qq.com:25","目标邮箱","邮件标题","邮件内容","html")

err := SendMail("1442919817@qq.com","zfyxxxxxx252078",username+"@qq.com","找回密码","点击这里修改密码:http://www.xxx.com/updatepass?username="+username+"&time="+time.Now().Format("2006-01-0215:04:05"),"html")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读