Files
2021-09-28 11:47:19 +08:00

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package lib
import (
"gopkg.in/gomail.v2"
)
type Email struct {
*EmailOption
}
type EmailOption struct {
User, Auth string // Auth定义邮箱服务器连接信息如果是阿里邮箱 Auth填密码qq邮箱填授权码
Host string
Port int
}
type EmailSendHandle func(objects []string, subject, body string) error
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)
}
}
func NewEmail(option *EmailOption) *Email {
return &Email{option}
}