go-pkgz / email

Email library to send simple messages
https://go-pkgz.umputun.dev/email/
MIT License
21 stars 6 forks source link

Login Auth #14

Closed Threnklyn closed 1 year ago

Threnklyn commented 2 years ago

https://github.com/umputun/remark42/issues/1472

looks like Microsoft does not allow Plain Auth anymore, which is used in go-pkgz/email/email.go. The go net/smtp package does not support the login mechanism LOGIN. Here is an example I found for login auth using net/smtp https://gist.github.com/homme/22b457eb054a07e7b2fb

gurza commented 1 year ago

I can implement LOGIN authorization mechanism in /pkg/auth.go. Also I suggest adding an auth field to Sender struct instead of smtpUserName and smtpPassword fields, look at listing below. It will require to rewrite the Sender constructor and auth check in Send() method. @umputun If you do not mind this approach, I will send a PR.

type Sender struct {
    smtpClient     SMTPClient
    logger         Logger
    host           string // SMTP host
    port           int    // SMTP port
    contentType    string // Content type, optional. Will trigger MIME and Content-Type headers
    tls            bool   // TLS auth
    starttls       bool   // StartTLS

    auth smtp.Auth  // authentication mechanism
    // smtpUserName   string // username
    // smtpPassword   string // password

    timeOut        time.Duration
    contentCharset string
    timeNow        func() time.Time
}
umputun commented 1 year ago

As long as the current Auth(smtpUserName, smtpPasswd string) Option is kept untouched and back compatibility is not broken - fine with me.

gurza commented 1 year ago

@umputun please review my PR #15