Skip to content

Commit

Permalink
Remove redundant SMTP LOGIN auth implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed May 16, 2020
1 parent 69d3e9b commit abddcb9
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions internal/messenger/emailer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package messenger

import (
"errors"
"fmt"
"math/rand"
"net/smtp"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit abddcb9

Please sign in to comment.