fix: Allow Auth over non-TLS SMTP connections (#6402)

* fix: Allow Auth over non-TLS SMTP connections

* remove unused struct

---------

Co-authored-by: Kitsune <kitsune@akitsune.dev>
Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Gabriel Enrico 2023-08-29 11:37:30 -04:00 committed by GitHub
parent f07e40c70b
commit 14d799e750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -159,7 +159,9 @@ func (smtpConfig SMTP) smtpAuth(client *smtp.Client, host string) error {
return nil
}
// Auth
auth := smtp.PlainAuth("", smtpConfig.User, smtpConfig.Password, host)
auth := unencryptedAuth{
smtp.PlainAuth("", smtpConfig.User, smtpConfig.Password, host),
}
err := client.Auth(auth)
if err != nil {
return caos_errs.ThrowInternalf(err, "EMAIL-s9kfs", "could not add smtp auth for user %s", smtpConfig.User)

View File

@ -0,0 +1,22 @@
package smtp
import (
"net/smtp"
)
type unencryptedAuth struct {
smtp.Auth
}
// PlainAuth returns an Auth that implements the PLAIN authentication
// mechanism as defined in RFC 4616. The returned Auth uses the given
// username and password to authenticate to host and act as identity.
// Usually identity should be the empty string, to act as username.
//
// This reimplementation allows it to work over non-TLS connections
func (a unencryptedAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
s := *server
s.TLS = true
return a.Auth.Start(&s)
}