Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme: check auth #222

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,38 @@ func (bkd *Backend) NewSession(_ *smtp.Conn) (smtp.Session, error) {
}

// A Session is returned after EHLO.
type Session struct{}
type Session struct {
auth bool
}

func (s *Session) AuthPlain(username, password string) error {
if username != "username" || password != "password" {
return errors.New("Invalid username or password")
}
s.auth = true
return nil
}

func (s *Session) Mail(from string, opts *smtp.MailOptions) error {
if !s.auth {
return ErrAuthRequired
}
log.Println("Mail from:", from)
return nil
}

func (s *Session) Rcpt(to string) error {
if !s.auth {
return ErrAuthRequired
}
log.Println("Rcpt to:", to)
return nil
}

func (s *Session) Data(r io.Reader) error {
if !s.auth {
return ErrAuthRequired
}
if b, err := ioutil.ReadAll(r); err != nil {
return err
} else {
Expand Down