1 Star 0 Fork 0

world100/go_lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
53_发送邮件.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
world100 提交于 2021-06-21 17:30 . go lib
package main
import (
"fmt"
"net/smtp"
"strconv"
"strings"
)
func SendToMail(user, password, host, to, subject, body, mailtype string) error {
hp := strings.Split(host, ":")
auth := smtp.PlainAuth("", user, password, 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 + ">\r\nSubject: " + "\r\n" + content_type + "\r\n\r\n" + body)
send_to := strings.Split(to, ";")
err := smtp.SendMail(host, auth, user, send_to, msg)
return err
}
func main() {
num := 1.2
str := strconv.Itoa(int(num))
fmt.Println("str", str)
user := "yang**@yun*.com"
password := "***"
host := "smtp.exmail.qq.com:25"
subject := "使用Golang发送邮件"
body := `
<html>
<body>
<h3>
"Test send to email"
</h3>
</body>
</html>
`
fmt.Println("send email")
err := SendToMail(user, password, host, to, subject, body, "html")
if err != nil {
fmt.Println("Send mail error!")
fmt.Println(err)
} else {
fmt.Println("Send mail success!")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/world100/go_lib.git
[email protected]:world100/go_lib.git
world100
go_lib
go_lib
master

搜索帮助