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

44 lines
792 B

package gomail
import (
"fmt"
mailV2 "gopkg.in/gomail.v2"
"strings"
)
type Options struct {
MailHost string
MailPort int
MailUser string // 发件人
MailPass string // 发件人密码
MailTo string // 收件人 多个用,分割
Subject string // 邮件主题
Body string // 邮件内容
}
func Send(o *Options) error {
m := mailV2.NewMessage()
//设置发件人
m.SetHeader("From", o.MailUser)
//设置发送给多个用户
mailArrTo := strings.Split(o.MailTo, ",")
m.SetHeader("To", mailArrTo...)
//设置邮件主题
m.SetHeader("Subject", o.Subject)
//设置邮件正文
m.SetBody("text/html", o.Body)
d := mailV2.NewDialer(o.MailHost, o.MailPort, o.MailUser, o.MailPass)
err := d.DialAndSend(m)
if err != nil {
fmt.Println(err)
}
return err
}