Created
October 4, 2013 09:27
-
-
Save cryptix/6823336 to your computer and use it in GitHub Desktop.
implements the smtp.Auth interface to use AUTH with the LOGIN scheme.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mailing helpers | |
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", nil, nil | |
} | |
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) { | |
if more { | |
switch string(fromServer) { | |
case "Username:": | |
buf := []byte(fmt.Sprintf("%s", a.username)) | |
return buf, nil | |
case "Password:": | |
buf := []byte(fmt.Sprintf("%s", a.password)) | |
return buf, nil | |
default: | |
return nil, fmt.Errorf("Unknown next from server") | |
} | |
} | |
return nil, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment