package utils

import (
	"gopkg.in/gomail.v2"
	"strconv"
)

func SendMail(mailTo string, subject string, body string) error {
	//定义邮箱服务器连接信息
	mailConn := map[string]string{
		"user": "younggeetech@younggee.com",
		"pass": "mjaMGU448GZzcG38",
		"host": "smtp.exmail.qq.com",
		"port": "465",
	}
	//转换端口类型为int
	port, _ := strconv.Atoi(mailConn["port"])
	m := gomail.NewMessage()
	//这种方式可以添加别名，即“XX官方”
	m.SetHeader("From", m.FormatAddress(mailConn["user"], "youngji官方"))
	//发送给用户
	m.SetHeader("To", mailTo)
	//设置邮件主题
	m.SetHeader("Subject", subject)
	//设置邮件正文
	m.SetBody("text/html", body)
	d := gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"])
	err := d.DialAndSend(m)
	return err

}
