You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package controllers
import (
"crypto/tls"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
"gopkg.in/gomail.v2"
"html/template"
"io"
"os"
)
type SendEmailController struct {
beego.Controller
}
// @Title SendEmail
// @Description 发送邮件a
// @router /email [get]
func (c *SendEmailController) Email() {
email := c.Ctx.Input.Query("email")
if email == "" {
//c.Ctx.WriteString("接收的邮件地址必填" )
email = "hwf452@163.com"
}
subject := "MT4开单信号提示"
m := gomail.NewMessage()
m.SetHeader("From", "273217031@qq.com")
//m.SetHeader("To", "273217031@qq.com")
m.SetHeader("To", email)
if subject == "" {
m.SetHeader("Subject", "Hello!")
} else {
m.SetHeader("Subject", subject)
}
emailContent := "黄金做多开单触发5分钟周期开单信号"
data := map[string]interface{}{"UserName": "273217031@qq.com", "From": "273217031@qq.com", "To": email, "emailContent": emailContent}
t3, errHtml := template.ParseFiles("body.html") //将一个文件读作模板
if errHtml != nil {
logs.Debug("errHtml")
}
t3.Execute(os.Stdout, data)
m.AddAlternativeWriter("text/html", func(w io.Writer) error {
return t3.Execute(w, data)
})
d := gomail.NewDialer("smtp.qq.com", 465, "273217031@qq.com", "kvppflvecaekbiei")
d.TLSConfig = &tls.Config{ServerName: "smtp.qq.com", InsecureSkipVerify: true}
if err := d.DialAndSend(m); err != nil {
logs.Debug(err)
}
logs.Debug(email)
c.ServeJSON()
}