Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions auth.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gomail

import (
"bytes"
"errors"
"fmt"
"net/smtp"
"strings"
)

// loginAuth is an smtp.Auth that implements the LOGIN authentication mechanism.
Expand Down Expand Up @@ -38,12 +38,17 @@ func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
return nil, nil
}

cmd := string(fromServer)
cmd = strings.TrimSpace(cmd)
cmd = strings.TrimSuffix(cmd, ":")
cmd = strings.ToLower(cmd)

switch {
case bytes.Equal(fromServer, []byte("Username:")):
case strings.EqualFold(cmd,"username"):
return []byte(a.username), nil
case bytes.Equal(fromServer, []byte("Password:")):
case strings.EqualFold(cmd,"password"):
return []byte(a.password), nil
default:
return nil, fmt.Errorf("gomail: unexpected server challenge: %s", fromServer)
return nil, fmt.Errorf("gomail: unexpected server challenge: %s", cmd)
}
}
}
3 changes: 1 addition & 2 deletions smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ func (d *Dialer) Dial() (SendCloser, error) {
if ok, auths := c.Extension("AUTH"); ok {
if strings.Contains(auths, "CRAM-MD5") {
d.Auth = smtp.CRAMMD5Auth(d.Username, d.Password)
} else if strings.Contains(auths, "LOGIN") &&
!strings.Contains(auths, "PLAIN") {
} else if strings.Contains(auths, "LOGIN") {
d.Auth = &loginAuth{
username: d.Username,
password: d.Password,
Expand Down