Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors by use port 465 #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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