Files
2021-10-22 17:10:43 +08:00

41 lines
986 B
Go
Raw Permalink 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 {
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() {
}
func (this *Email) Send() EmailSendHandle {
return func(objects []string, subject, body string) error {
m := gomail.NewMessage()
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)
}
}
func NewEmail(option *EmailOption) *Email {
return &Email{option}
}