email-outlook-auth.go 621 B

1234567891011121314151617181920212223242526272829303132
  1. package common
  2. import (
  3. "errors"
  4. "net/smtp"
  5. )
  6. type outlookAuth struct {
  7. username, password string
  8. }
  9. func LoginAuth(username, password string) smtp.Auth {
  10. return &outlookAuth{username, password}
  11. }
  12. func (a *outlookAuth) Start(_ *smtp.ServerInfo) (string, []byte, error) {
  13. return "LOGIN", []byte{}, nil
  14. }
  15. func (a *outlookAuth) Next(fromServer []byte, more bool) ([]byte, error) {
  16. if more {
  17. switch string(fromServer) {
  18. case "Username:":
  19. return []byte(a.username), nil
  20. case "Password:":
  21. return []byte(a.password), nil
  22. default:
  23. return nil, errors.New("unknown fromServer")
  24. }
  25. }
  26. return nil, nil
  27. }