Skip to content

fix(smtp): AUTH username sets the project again - #358

Merged
butschster merged 1 commit into
masterfrom
fix/smtp-auth-project
Nov 6, 2026
Merged

butschster merged 1 commit into
masterfrom
fix/smtp-auth-project

Conversation

@butschster

Copy link
Copy Markdown
Member

Fixes #343

Problem

In v2 the project key given as the SMTP AUTH username was ignored: every mail landed in the default project. go-smtp v0.24 offers AUTH only through the AuthSession interface (AuthMechanisms + Auth); the old AuthPlain method was never called, and clients got 504 Unsupported authentication mechanism.

Fix

  • session implements gosmtp.AuthSession with PLAIN (go-sasl) and LOGIN (a small server side; go-sasl ships only the client). The username — project or project@host — selects the project. Any password is accepted, as before.
  • Reset() no longer clears the project. go-smtp calls it after every message, while AUTH is per connection, so the second mail of a connection fell back to default.
  • github.com/emersion/go-sasl moved from indirect to direct dependency.

Tests

go vet ./...; go test ./internal/... ./modules/smtp/ -count=1

  • TestSMTPAuthSetsProject runs the real SMTP server on a spare port with the real event pipeline and in-memory SQLite, two mails per connection: PLAIN, PLAIN user@host, LOGIN → project; no AUTH → default. Against the old handler it fails with 504 Unsupported authentication mechanism.
  • TestSessionSetProject (renamed from TestSessionAuthPlain).

go-smtp v0.24 only offers AUTH through the AuthSession interface
(AuthMechanisms + Auth); the old AuthPlain method was never called, so
every mail landed in the default project and AUTH was refused with
504 Unsupported authentication mechanism.

The session now implements AuthSession with PLAIN (go-sasl) and LOGIN
(small server-side implementation; go-sasl has only the client). The
username, "project" or "project@host", selects the project. Reset no
longer clears the project: it runs after every message, while AUTH is
per connection, so later mails of the same connection kept the project.

Fixes #343
@butschster butschster added the type: bug Something is broken or behaves incorrectly label Nov 6, 2026
@butschster
butschster marked this pull request as ready for review November 6, 2026 10:33
@butschster
butschster merged commit af97063 into master Nov 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2 Regression: SMTP project assignment no longer works.

1 participant