forked from drew/smtprelay
Support LOGIN authentication on outgoing SMTP server
PR: #1 Obtained from: https://gist.github.com/andelf/5118732
This commit is contained in:
@@ -25,6 +25,7 @@ var (
|
||||
remoteHost = flag.String("remote_host", "smtp.gmail.com:587", "Outgoing SMTP server")
|
||||
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
|
||||
remotePass = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
|
||||
remoteAuth = flag.String("remote_auth", "plain", "Auth method on outgoing SMTP server (plain, login)")
|
||||
remoteSender = flag.String("remote_sender", "", "Sender e-mail address on outgoing SMTP server")
|
||||
versionInfo = flag.Bool("version", false, "Show version information")
|
||||
)
|
||||
|
||||
9
main.go
9
main.go
@@ -110,7 +110,14 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
||||
host, _, _ := net.SplitHostPort(*remoteHost)
|
||||
|
||||
if *remoteUser != "" && *remotePass != "" {
|
||||
auth = smtp.PlainAuth("", *remoteUser, *remotePass, host)
|
||||
switch *remoteAuth {
|
||||
case "plain":
|
||||
auth = smtp.PlainAuth("", *remoteUser, *remotePass, host)
|
||||
case "login":
|
||||
auth = LoginAuth(*remoteUser, *remotePass)
|
||||
default:
|
||||
return smtpd.Error{Code: 530, Message: "Authentication method not supported"}
|
||||
}
|
||||
}
|
||||
|
||||
env.AddReceivedLine(peer)
|
||||
|
||||
27
smtp.go
27
smtp.go
@@ -451,3 +451,30 @@ func validateLine(line string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LOGIN authentication
|
||||
type loginAuth struct {
|
||||
username, password string
|
||||
}
|
||||
|
||||
func LoginAuth(username, password string) smtp.Auth {
|
||||
return &loginAuth{username, password}
|
||||
}
|
||||
|
||||
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 fromServer")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -55,5 +55,9 @@
|
||||
;remote_user =
|
||||
;remote_pass =
|
||||
|
||||
; Authentication method on outgoing SMTP server
|
||||
; (plain, login)
|
||||
;remote_auth = plain
|
||||
|
||||
; Sender e-mail address on outgoing SMTP server
|
||||
;remote_sender =
|
||||
|
||||
Reference in New Issue
Block a user