golang(beego) 发送邮件

golang(beego) 发送邮件,第1张

概述import ( "net/smtp" "strings")//发送邮件帮助类func SendMail(user, password, host, to, subject, body, mailtype string) error { hp := strings.Split(host, ":") auth := smtp.PlainAuth("", user, password
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 + "\r\nFrom: " + user + "<" + user + ">\r\nSubject: " + subject + "\r\n" + content_type + "\r\n\r\n" + 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")
总结

以上是内存溢出为你收集整理的golang(beego) 发送邮件全部内容,希望文章能够帮你解决golang(beego) 发送邮件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1289426.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-09
下一篇2022-06-09

发表评论

登录后才能评论

评论列表(0条)

    保存