Skip to content

Make the SMTP authentication mechanism configurable - #507

Open
DsgnrFH wants to merge 2 commits into
mainfrom
feature/email-auth-mechanism
Open

Make the SMTP authentication mechanism configurable#507
DsgnrFH wants to merge 2 commits into
mainfrom
feature/email-auth-mechanism

Conversation

@DsgnrFH

@DsgnrFH DsgnrFH commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Resolves #474

@DsgnrFH
DsgnrFH requested a review from yhabteab September 2, 2026 12:20
@DsgnrFH DsgnrFH self-assigned this Sep 2, 2026
@DsgnrFH DsgnrFH added the go Pull requests that update Go code label Sep 2, 2026
@cla-bot cla-bot Bot added the cla/signed CLA is signed by all contributors of a PR label Sep 2, 2026
Comment on lines +38 to +46
const (
// AuthMechanismAuto picks the SASL mechanism.
AuthMechanismAuto = "auto"
// AuthMechanismPlain enforces the SASL PLAIN mechanism.
AuthMechanismPlain = "plain"
// AuthMechanismLogin enforces the still widely deployed SASL LOGIN mechanism
AuthMechanismLogin = "login"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need these constants? Why not just use the ones from the sasl package instead?

Password string `json:"password"` // #nosec G117 -- exported password field
Encryption string `json:"encryption"`
// AuthMechanism is one of: AuthMechanismAuto, AuthMechanismPlain or AuthMechanismLogin.
AuthMechanism string `json:"auth_mechanism"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be called auth_method instead.


if password != "" {
if err = client.Auth(sasl.NewPlainClient("", username, password)); err != nil {
auth, err := saslClient(client, authMechanism, username, password)

@yhabteab yhabteab Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now guarded by the password check, but shouldn't we already discussed offline that atleast the sasl.OAuthBearer auth method should be supported as well, which doesn't require a password?

// LOGIN mechanism. This requires an already greeted client, which is the case after the first contact.
func saslClient(client *smtp.Client, mechanism, username, password string) (sasl.Client, error) {
switch mechanism {
case AuthMechanismAuto:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the auto options. The user should know which auth method is supported by the SMTP server he's planning to use. No, need to figure this out on our own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed CLA is signed by all contributors of a PR go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support SMTP AUTH LOGIN in addition to PLAIN

2 participants