package email import ( "yunyan/lego/sys/log" "yunyan/lego/utils/mapstructure" ) type EmailType uint8 const ( QQEmail EmailType = iota //QQ邮箱 TencentEmail //腾讯企业邮箱 GmailEmail //Google邮箱 ResendEmail //Resend(HTTP API 发信,海外送达率优,Password 字段填 API Key) ) type Option func(*Options) type Options struct { EmailType EmailType FromEmail string FromName string Password string } func Set_EmailType(v EmailType) Option { return func(o *Options) { o.EmailType = v } } func Set_FromEmail(v string) Option { return func(o *Options) { o.FromEmail = v } } func Set_FromName(v string) Option { return func(o *Options) { o.FromName = v } } func Set_Password(v string) Option { return func(o *Options) { o.Password = v } } func newOptions(config map[string]interface{}, opts ...Option) Options { options := Options{} if config != nil { mapstructure.Decode(config, &options) } for _, o := range opts { o(&options) } if options.FromEmail == "" || options.Password == "" { log.Panicf("start email Missing necessary configuration : Serverhost:%s Fromemail:%s Fompasswd:%s", options.FromEmail, options.EmailType) } return options } func newOptionsByOption(opts ...Option) Options { options := Options{} for _, o := range opts { o(&options) } if options.FromEmail == "" || options.Password == "" { log.Panicf("start email Missing necessary configuration : Serverhost:%s Fromemail:%s Fompasswd:%s", options.FromEmail, options.EmailType) } return options }