-
Notifications
You must be signed in to change notification settings - Fork 582
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
504 5.7.4 Unrecognized authentication type #16
Comments
You should try to use you own Auth mechanism. Then use gomail.NewCustomMailer to use your new auth mechanism. |
Ok, I'll ping you when I get it. Thanks! |
Hey, I found time to work on it! :) type loginAuth struct {
identity, username, password string
host string
}
// loginAuth returns an Auth that implements the LOGIN authentication
// mechanism as defined in RFC 4616.
// The returned Auth uses the given username and password to authenticate
// on TLS connections to host and act as identity. Usually identity will be
// left blank to act as username.
func LoginAuth(identity, username, password, host string) smtp.Auth {
return &loginAuth{identity, username, password, host}
}
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
if !server.TLS {
advertised := false
for _, mechanism := range server.Auth {
if mechanism == "LOGIN" {
advertised = true
break
}
}
if !advertised {
return "", nil, errors.New("unencrypted connection")
}
}
if server.Name != a.host {
return "", nil, errors.New("wrong host name")
}
resp := []byte(a.identity + "\x00" + a.username + "\x00" + a.password)
return "LOGIN", resp, nil
}
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
// log.Println("NEXT: ", fromServer)
if more {
// We've already sent everything.
return nil, errors.New("unexpected server challenge")
}
return nil, nil
} Then, create mailer with this: mailer := gomail.NewCustomMailer("smtp.office365.com:587", LoginAuth("", "[email protected]", "password", "smtp.office365.com")) But I'm getting error from If you see the implementation on SwiftMailer the commands sent are with different notation: AuthPlain: https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php#L41 I don't know how to change this... too late :( Can you help me? Thanks!!! |
Ok I think the first command is just $agent->executeCommand("AUTH LOGIN\r\n", array(334));
$agent->executeCommand(sprintf("%s\r\n", base64_encode($username)), array(334));
$agent->executeCommand(sprintf("%s\r\n", base64_encode($password)), array(235)); So, to do this, in So, two questions, how to know if I'm sending the first (username) or second (password) parameter? So now the question is how to encode the two commands to the server... func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
log.Println("NEXT: ", fromServer)
// if more {
// // We've already sent everything.
// return nil, errors.New("unexpected server challenge")
// }
if more {
if (a.authInit == true) {
a.authInit = false
return []byte(fmt.Sprintf("%s %x", a.username, 334)), nil
} else {
return []byte(fmt.Sprintf("%s %x", a.password, 235)), nil
}
}
return nil, nil
} Don't know how to set the second parameter of |
Sorry I do not have the issue so I cannot help you much. 334 and 235 are not parameters on Sprintf but of executeCommand in the Swiftmailer code. So you should try removing them. |
I suppose the spec needs some length or code at the end of the command: func (a *cramMD5Auth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
d := hmac.New(md5.New, []byte(a.secret))
d.Write(fromServer)
s := make([]byte, 0, d.Size())
return []byte(fmt.Sprintf("%s %x", a.username, d.Sum(s))), nil
}
return nil, nil
} I'm just asking for your help because you played with the SMTP protocol right? :) |
Yayyyy it works!!! I just have to follow the spec hehe: I think I will send a pull request for "net/smtp/auth.go" :) but first I need to clean up things and make some tests. Thanks! |
Ok, while it's accepted as a pull request (if there's a chance) how you will deal with this "bug"? |
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: Not sure why I don't need to use base64 to decode server commands and encode user and password :/ |
Good job ! It is a bit difficult to do the fix since I cannot create an account on office365. Could you send the content of:
|
On
|
Thanks! I commited a new function on a new branch, can you try it to see if it works? See the readme for more details. |
Sorry for the delay! Checked that it works perfectly!!! :D 💃 Will you create a new version? How I have to update it? Thanks! |
In case it will be included in SMTP standard library. |
I merged the branch. You can do Gmail works well on the PLAIN mechanism and using this new auth is not needed. |
Perfect! Thanks a lot! |
I landed here after receiving the error from the Go standard library I am on Go version 1.10.3 and I am a bit surprised this issue (error/bug?) is still in there. |
From golang-nuts: https://groups.google.com/d/msg/golang-nuts/ywPpNlmSt6U/0Mxttkx9kgQJ
Returns error
504 5.7.4 Unrecognized authentication type
The text was updated successfully, but these errors were encountered: