Backport #21767
The purpose of #18982 is to improve the SMTP mailer, but there were some
unrelated changes made to the SMTP auth in
d60c438694
This PR reverts these unrelated changes, fix #21744
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
87d05d376d
commit
3aacc9b4ac
6 changed files with 11 additions and 11 deletions
|
@ -413,9 +413,9 @@ var (
|
||||||
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
|
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "addr",
|
Name: "host",
|
||||||
Value: "",
|
Value: "",
|
||||||
Usage: "SMTP Addr",
|
Usage: "SMTP Host",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "port",
|
Name: "port",
|
||||||
|
@ -955,8 +955,8 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
|
||||||
}
|
}
|
||||||
conf.Auth = c.String("auth-type")
|
conf.Auth = c.String("auth-type")
|
||||||
}
|
}
|
||||||
if c.IsSet("addr") {
|
if c.IsSet("host") {
|
||||||
conf.Addr = c.String("addr")
|
conf.Host = c.String("host")
|
||||||
}
|
}
|
||||||
if c.IsSet("port") {
|
if c.IsSet("port") {
|
||||||
conf.Port = c.Int("port")
|
conf.Port = c.Int("port")
|
||||||
|
|
|
@ -159,7 +159,7 @@ func parseLDAPConfig(form forms.AuthenticationForm) *ldap.Source {
|
||||||
func parseSMTPConfig(form forms.AuthenticationForm) *smtp.Source {
|
func parseSMTPConfig(form forms.AuthenticationForm) *smtp.Source {
|
||||||
return &smtp.Source{
|
return &smtp.Source{
|
||||||
Auth: form.SMTPAuth,
|
Auth: form.SMTPAuth,
|
||||||
Addr: form.SMTPAddr,
|
Host: form.SMTPHost,
|
||||||
Port: form.SMTPPort,
|
Port: form.SMTPPort,
|
||||||
AllowedDomains: form.AllowedDomains,
|
AllowedDomains: form.AllowedDomains,
|
||||||
ForceSMTPS: form.ForceSMTPS,
|
ForceSMTPS: form.ForceSMTPS,
|
||||||
|
|
|
@ -58,10 +58,10 @@ var ErrUnsupportedLoginType = errors.New("Login source is unknown")
|
||||||
func Authenticate(a smtp.Auth, source *Source) error {
|
func Authenticate(a smtp.Auth, source *Source) error {
|
||||||
tlsConfig := &tls.Config{
|
tlsConfig := &tls.Config{
|
||||||
InsecureSkipVerify: source.SkipVerify,
|
InsecureSkipVerify: source.SkipVerify,
|
||||||
ServerName: source.Addr,
|
ServerName: source.Host,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := net.Dial("tcp", net.JoinHostPort(source.Addr, strconv.Itoa(source.Port)))
|
conn, err := net.Dial("tcp", net.JoinHostPort(source.Host, strconv.Itoa(source.Port)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func Authenticate(a smtp.Auth, source *Source) error {
|
||||||
conn = tls.Client(conn, tlsConfig)
|
conn = tls.Client(conn, tlsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := smtp.NewClient(conn, source.Addr)
|
client, err := smtp.NewClient(conn, source.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create NewClient: %w", err)
|
return fmt.Errorf("failed to create NewClient: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// Source holds configuration for the SMTP login source.
|
// Source holds configuration for the SMTP login source.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Auth string
|
Auth string
|
||||||
Addr string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
AllowedDomains string `xorm:"TEXT"`
|
AllowedDomains string `xorm:"TEXT"`
|
||||||
ForceSMTPS bool
|
ForceSMTPS bool
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
|
||||||
var auth smtp.Auth
|
var auth smtp.Auth
|
||||||
switch source.Auth {
|
switch source.Auth {
|
||||||
case PlainAuthentication:
|
case PlainAuthentication:
|
||||||
auth = smtp.PlainAuth("", userName, password, source.Addr)
|
auth = smtp.PlainAuth("", userName, password, source.Host)
|
||||||
case LoginAuthentication:
|
case LoginAuthentication:
|
||||||
auth = &loginAuthenticator{userName, password}
|
auth = &loginAuthenticator{userName, password}
|
||||||
case CRAMMD5Authentication:
|
case CRAMMD5Authentication:
|
||||||
|
|
|
@ -45,7 +45,7 @@ type AuthenticationForm struct {
|
||||||
IsActive bool
|
IsActive bool
|
||||||
IsSyncEnabled bool
|
IsSyncEnabled bool
|
||||||
SMTPAuth string
|
SMTPAuth string
|
||||||
SMTPAddr string
|
SMTPHost string
|
||||||
SMTPPort int
|
SMTPPort int
|
||||||
AllowedDomains string
|
AllowedDomains string
|
||||||
SecurityProtocol int `binding:"Range(0,2)"`
|
SecurityProtocol int `binding:"Range(0,2)"`
|
||||||
|
|
Loading…
Reference in a new issue