feat(email): negotiate SMTP AUTH mechanism, add Office 365 LOGIN support - #121
feat(email): negotiate SMTP AUTH mechanism, add Office 365 LOGIN support#121jackyhowh wants to merge 1 commit into
Conversation
|
Thanks for this contribution — the SMTP work is genuinely solid. I reviewed it in depth: the Office 365 LOGIN auth is correctly implemented (refuses non-TLS, negotiates post-STARTTLS), the multi-recipient parsing is safe against header injection, and sending a real test email is a clear UX improvement over the old dial-only check. That said, this PR bundles three unrelated changes, and I'd like to merge them on their own merits. Could you split it up?
Also, for transparency: the A tip for the split: branch each piece off current |
Go's net/smtp only ships PLAIN and CRAM-MD5. Office 365 / Outlook (smtp.office365.com) advertises only LOGIN and XOAUTH2, and rejects an AUTH PLAIN attempt with "504 5.7.4 Unrecognized authentication type". SMTPAuth negotiates PLAIN or LOGIN from the server's advertised mechanism list at handshake time, falling back to LOGIN when PLAIN isn't offered. The LOGIN implementation refuses to send credentials over a connection that hasn't negotiated TLS. Wires the negotiated auth into both the SMTP connection test and outgoing notification emails, replacing the hardcoded PlainAuth call in each.
Summary
Go's
net/smtponly ships PLAIN and CRAM-MD5. Office 365 / Outlook(
smtp.office365.com) advertises only LOGIN and XOAUTH2, and rejects anAUTH PLAIN attempt with
504 5.7.4 Unrecognized authentication type.SMTPAuthnegotiates PLAIN or LOGIN from the server's advertised mechanismlist at handshake time, falling back to LOGIN when PLAIN isn't offered. The
LOGIN implementation refuses to send credentials over a connection that
hasn't negotiated TLS.
Changes
internal/service/smtp_auth.go(new):SMTPAuthwith PLAIN/LOGINauto-negotiation, and a
loginAuthimplementation of the AUTH LOGINmechanism.
internal/service/email.go: outgoing notification emails use thenegotiated auth instead of a hardcoded
smtp.PlainAuth.internal/handlers/settings.go: the SMTP connection test uses the samenegotiated auth.
internal/service/smtp_auth_test.go: unit tests covering mechanismselection (PLAIN preferred, LOGIN fallback, default-to-PLAIN on unknown
mechanisms) and the TLS-refusal guard.
Test plan
go test ./...passesNote
This PR previously bundled a "real test email" feature and multi-recipient
support along with this LOGIN auth fix. Both have been pulled out: I found a
bug in the multi-recipient parsing after this was originally submitted, and
want to fix that properly before resubmitting it (along with the test-email
change) as its own PR. This PR is now scoped to the Office 365 LOGIN auth
negotiation only.