1
0

auth.go 718 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package smtp
  2. import (
  3. "fmt"
  4. "net/smtp"
  5. "strings"
  6. )
  7. type auth struct {
  8. username string
  9. password string
  10. }
  11. func (a auth) Start(_ *smtp.ServerInfo) (string, []byte, error) {
  12. return "LOGIN", nil, nil
  13. }
  14. func (a auth) Next(req []byte, more bool) ([]byte, error) {
  15. command := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(string(req)), ":"))
  16. if more {
  17. if command == "username" {
  18. return []byte(fmt.Sprintf("%s", a.username)), nil
  19. }
  20. if command == "password" {
  21. return []byte(fmt.Sprintf("%s", a.password)), nil
  22. }
  23. return nil, fmt.Errorf("unexpected server challenge: %s", command)
  24. }
  25. return nil, nil
  26. }
  27. func getAuth(username, password string) smtp.Auth {
  28. return &auth{username, password}
  29. }