feat:完善信息
This commit is contained in:
20
lib/email.go
20
lib/email.go
@ -9,11 +9,15 @@ type Email struct {
|
||||
}
|
||||
|
||||
type EmailOption struct {
|
||||
User, Auth string // Auth:定义邮箱服务器连接信息,如果是阿里邮箱 Auth填密码,qq邮箱填授权码
|
||||
Host string
|
||||
Port int
|
||||
Alias, User, Pass string // Auth:定义邮箱服务器连接信息,如果是阿里邮箱 Pass填密码,qq邮箱填授权码
|
||||
Host string
|
||||
Port int
|
||||
}
|
||||
|
||||
// EmailSendHandle 邮件发送处理
|
||||
// @objects:发送对象,多个邮件地址
|
||||
// @subject:邮件主题
|
||||
// @body:邮件正文
|
||||
type EmailSendHandle func(objects []string, subject, body string) error
|
||||
|
||||
func (this *Email) Init() {
|
||||
@ -23,11 +27,11 @@ func (this *Email) Init() {
|
||||
func (this *Email) Send() EmailSendHandle {
|
||||
return func(objects []string, subject, body string) error {
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", "XD Game"+"<"+this.User+">") //这种方式可以添加别名,即“XD Game”, 也可以直接用<code>m.SetHeader("From",mailConn["user"])</code> 读者可以自行实验下效果
|
||||
m.SetHeader("To", objects...) //发送给多个用户
|
||||
m.SetHeader("Subject", subject) //设置邮件主题
|
||||
m.SetBody("text/html", body) //设置邮件正文
|
||||
return gomail.NewDialer(this.Host, this.Port, this.User, this.Auth).DialAndSend(m)
|
||||
m.SetHeader("From", m.FormatAddress(this.User, this.Alias))
|
||||
m.SetHeader("To", objects...)
|
||||
m.SetHeader("Subject", subject)
|
||||
m.SetBody("text/html", body)
|
||||
return gomail.NewDialer(this.Host, this.Port, this.User, this.Pass).DialAndSend(m)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,24 +10,21 @@ import (
|
||||
func SendMail(mailTo []string, subject string, body string) error {
|
||||
//定义邮箱服务器连接信息,如果是阿里邮箱 pass填密码,qq邮箱填授权码
|
||||
mailConn := map[string]string{
|
||||
"user": "postmaster@ipeace.org.cn",
|
||||
"pass": "Email@henry!",
|
||||
"host": "smtp.qiye.aliyun.com",
|
||||
"port": "465",
|
||||
"alias": "postmaster",
|
||||
"user": "postmaster@ipeace.org.cn",
|
||||
"pass": "Email@henry!",
|
||||
"host": "smtp.qiye.aliyun.com",
|
||||
"port": "465",
|
||||
}
|
||||
port, _ := strconv.Atoi(mailConn["port"]) //转换端口类型为int
|
||||
|
||||
m := gomail.NewMessage()
|
||||
m.SetHeader("From", "XD Game"+"<"+mailConn["user"]+">") //这种方式可以添加别名,即“XD Game”, 也可以直接用<code>m.SetHeader("From",mailConn["user"])</code> 读者可以自行实验下效果
|
||||
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
|
||||
m.SetHeader("From", m.FormatAddress(mailConn["user"], mailConn["alias"]))
|
||||
m.SetHeader("To", mailTo...)
|
||||
m.SetHeader("Subject", subject)
|
||||
m.SetBody("text/html", body)
|
||||
|
||||
return gomail.NewDialer(mailConn["host"], port, mailConn["user"], mailConn["pass"]).DialAndSend(m)
|
||||
}
|
||||
|
||||
func TestNewEmail(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user