package mailer import ( "crypto/tls" "github.com/go-mail/mail" ) type Options struct { From string Host string Port int Username string Password string } type Mailer struct { dialer *mail.Dialer options *Options } func New(options *Options) *Mailer { dialer := mail.NewDialer(options.Host, options.Port, options.Username, options.Password) dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true} return &Mailer{ dialer: dialer, options: options, } } func (mailer *Mailer) Send(to, subject, text string) error { m := mail.NewMessage() m.SetHeader("From", mailer.options.From) m.SetHeader("To", to) m.SetHeader("Subject", subject) m.SetBody("text/plain", text) return mailer.dialer.DialAndSend(m) }