gomail: 504 5.7.4 Unrecognized authentication type

From golang-nuts: https://groups.google.com/d/msg/golang-nuts/ywPpNlmSt6U/0Mxttkx9kgQJ

mailer := gomail.NewMailer("smtp.office365.com", "f...@bar.com", "password", 587)

Returns error 504 5.7.4 Unrecognized authentication type

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s the code of LoginAuth:

type loginAuth struct {
    username, password string
}

// loginAuth returns an Auth that implements the LOGIN authentication
// mechanism as defined in RFC 4616.
func LoginAuth(username, password string) smtp.Auth {
    return &loginAuth{username, password}
}

func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
    return "LOGIN", nil, nil
}

func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
    command := string(fromServer)
    command = strings.TrimSpace(command)
    command = strings.TrimSuffix(command, ":")
    command = strings.ToLower(command)

    if more {
        if (command == "username") {
            return []byte(fmt.Sprintf("%s", a.username)), nil
        } else if (command == "password") {
            return []byte(fmt.Sprintf("%s", a.password)), nil
        } else {
            // We've already sent everything.
            return nil, fmt.Errorf("unexpected server challenge: %s", command)
        }
    }
    return nil, nil
}

Then call: mailer := gomail.NewCustomMailer("smtp.office365.com:587", LoginAuth("login@email.com", "password")).

Not sure why I don’t need to use base64 to decode server commands and encode user and password 😕