Remove redundant SMTP LOGIN auth implementation

This commit is contained in:
Kailash Nadh 2020-05-16 23:38:19 +05:30
parent 69d3e9b9c8
commit abddcb9a03
1 changed files with 1 additions and 28 deletions

View File

@ -1,7 +1,6 @@
package messenger package messenger
import ( import (
"errors"
"fmt" "fmt"
"math/rand" "math/rand"
"net/smtp" "net/smtp"
@ -12,12 +11,6 @@ import (
const emName = "email" const emName = "email"
// loginAuth is used for enabling SMTP "LOGIN" auth.
type loginAuth struct {
username string
password string
}
// Server represents an SMTP server's credentials. // Server represents an SMTP server's credentials.
type Server struct { type Server struct {
Name string Name string
@ -56,7 +49,7 @@ func NewEmailer(srv ...Server) (*Emailer, error) {
case "plain": case "plain":
auth = smtp.PlainAuth("", s.Username, s.Password, s.Host) auth = smtp.PlainAuth("", s.Username, s.Password, s.Host)
case "login": case "login":
auth = &loginAuth{username: s.Username, password: s.Password} auth = &smtppool.LoginAuth{Username: s.Username, Password: s.Password}
case "": case "":
default: default:
return nil, fmt.Errorf("unknown SMTP auth type '%s'", s.AuthProtocol) return nil, fmt.Errorf("unknown SMTP auth type '%s'", s.AuthProtocol)
@ -139,23 +132,3 @@ func (e *Emailer) Push(fromAddr string, toAddr []string, subject string, m []byt
func (e *Emailer) Flush() error { func (e *Emailer) Flush() error {
return nil return nil
} }
// https://gist.github.com/andelf/5118732
// Adds support for SMTP LOGIN auth.
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
return "LOGIN", []byte{}, nil
}
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
switch string(fromServer) {
case "Username:":
return []byte(a.username), nil
case "Password:":
return []byte(a.password), nil
default:
return nil, errors.New("unkown SMTP fromServer")
}
}
return nil, nil
}