Skip to content

Commit

Permalink
Merge pull request #17 from k1LoW/fix-no-auth
Browse files Browse the repository at this point in the history
Allow defining cases where authentication is not supported
  • Loading branch information
k1LoW committed Mar 29, 2024
2 parents 2a49b8a + 68d3841 commit 90c2461
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions smtptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func (s *Session) Logout() error {
}

func (s *Session) AuthMechanisms() []string {
if s.be.username == nil {
return nil
}
return []string{sasl.Plain}
}

func (s *Session) Auth(mech string) (sasl.Server, error) {
if s.be.username == nil {
return sasl.NewPlainServer(func(identity, username, password string) error {
return nil
}), nil
return nil, smtp.ErrAuthUnsupported
}
return sasl.NewPlainServer(func(identity, username, password string) error {
if identity != "" && identity != username {
Expand Down
6 changes: 2 additions & 4 deletions smtptest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func TestServer(t *testing.T) {
})

addr := ts.Addr()
auth := smtp.PlainAuth("", "user@example.com", "password", ts.Host)
if err := smtp.SendMail(addr, auth, "sender@example.org", []string{"recipient@example.net"}, []byte(testMsg)); err != nil {
if err := smtp.SendMail(addr, nil, "sender@example.org", []string{"recipient@example.net"}, []byte(testMsg)); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -136,8 +135,7 @@ func TestServerMultipleRecipients(t *testing.T) {
})

addr := ts.Addr()
auth := smtp.PlainAuth("", "user@example.com", "password", ts.Host)
if err := smtp.SendMail(addr, auth, "sender@example.org", []string{"recipient@example.net", "another_recipient@example.net"}, []byte(testMsg)); err != nil {
if err := smtp.SendMail(addr, nil, "sender@example.org", []string{"recipient@example.net", "another_recipient@example.net"}, []byte(testMsg)); err != nil {
t.Fatal(err)
}

Expand Down

0 comments on commit 90c2461

Please sign in to comment.