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

View file

@ -1,7 +1,6 @@
package messenger
import (
"errors"
"fmt"
"math/rand"
"net/smtp"
@ -12,12 +11,6 @@ import (
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.
type Server struct {
Name string
@ -56,7 +49,7 @@ func NewEmailer(srv ...Server) (*Emailer, error) {
case "plain":
auth = smtp.PlainAuth("", s.Username, s.Password, s.Host)
case "login":
auth = &loginAuth{username: s.Username, password: s.Password}
auth = &smtppool.LoginAuth{Username: s.Username, Password: s.Password}
case "":
default:
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 {
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
}