-
Notifications
You must be signed in to change notification settings - Fork 20
/
auth.go
34 lines (29 loc) · 835 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"fmt"
"net/smtp"
)
type loginAuth struct {
username, password string
}
// LoginAuth provides a simple implementation of LOGIN authorization of SMTP as
// described here: https://www.ietf.org/archive/id/draft-murchison-sasl-login-00.txt
func LoginAuth(username, password string) smtp.Auth {
return &loginAuth{username, password}
}
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
return "LOGIN", []byte{}, nil
}
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
switch string(fromServer) {
case "User Name", "Username:":
return []byte(a.username), nil
case "Password", "Password:":
return []byte(a.password), nil
default:
return nil, fmt.Errorf("unknown server response \"%s\"", string(fromServer))
}
}
return nil, nil
}