hydra-passwordless/internal/mail/mailer.go

53 lines
898 B
Go
Raw Normal View History

2020-04-08 08:56:42 +02:00
package mail
2020-04-24 09:27:07 +02:00
const (
ContentTypeHTML = "text/html"
ContentTypeText = "text/plain"
)
2020-04-08 08:56:42 +02:00
type Option struct {
Host string
Port int
User string
Password string
InsecureSkipVerify bool
2020-04-24 09:27:07 +02:00
UseStartTLS bool
2020-04-08 08:56:42 +02:00
}
type OptionFunc func(*Option)
type Mailer struct {
opt *Option
}
2020-04-24 09:27:07 +02:00
func WithTLS(useStartTLS, insecureSkipVerify bool) OptionFunc {
return func(opt *Option) {
opt.UseStartTLS = useStartTLS
opt.InsecureSkipVerify = insecureSkipVerify
}
}
func WithServer(host string, port int) OptionFunc {
return func(opt *Option) {
opt.Host = host
opt.Port = port
}
}
func WithCredentials(user, password string) OptionFunc {
return func(opt *Option) {
opt.User = user
opt.Password = password
}
}
2020-04-08 08:56:42 +02:00
func NewMailer(funcs ...OptionFunc) *Mailer {
2020-04-24 09:27:07 +02:00
opt := &Option{}
for _, fn := range funcs {
fn(opt)
}
return &Mailer{opt}
2020-04-08 08:56:42 +02:00
}