Skip to content

Instantly share code, notes, and snippets.

@cryptix
Created October 4, 2013 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptix/6823336 to your computer and use it in GitHub Desktop.
Save cryptix/6823336 to your computer and use it in GitHub Desktop.
implements the smtp.Auth interface to use AUTH with the LOGIN scheme.
// 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