Backport #21767
The purpose of #18982 is to improve the SMTP mailer, but there were some
unrelated changes made to the SMTP auth in
https://github.com/go-gitea/gitea/pull/18982/commits/
d60c43869420f5fc43ad19b454c9ae50dad65964
This PR reverts these unrelated changes, fix #21744
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Usage: "SMTP Authentication Type (PLAIN/LOGIN/CRAM-MD5) default PLAIN",
},
cli.StringFlag{
- Name: "addr",
+ Name: "host",
Value: "",
- Usage: "SMTP Addr",
+ Usage: "SMTP Host",
},
cli.IntFlag{
Name: "port",
}
conf.Auth = c.String("auth-type")
}
- if c.IsSet("addr") {
- conf.Addr = c.String("addr")
+ if c.IsSet("host") {
+ conf.Host = c.String("host")
}
if c.IsSet("port") {
conf.Port = c.Int("port")
func parseSMTPConfig(form forms.AuthenticationForm) *smtp.Source {
return &smtp.Source{
Auth: form.SMTPAuth,
- Addr: form.SMTPAddr,
+ Host: form.SMTPHost,
Port: form.SMTPPort,
AllowedDomains: form.AllowedDomains,
ForceSMTPS: form.ForceSMTPS,
func Authenticate(a smtp.Auth, source *Source) error {
tlsConfig := &tls.Config{
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 {
return err
}
conn = tls.Client(conn, tlsConfig)
}
- client, err := smtp.NewClient(conn, source.Addr)
+ client, err := smtp.NewClient(conn, source.Host)
if err != nil {
return fmt.Errorf("failed to create NewClient: %w", err)
}
// Source holds configuration for the SMTP login source.
type Source struct {
Auth string
- Addr string
+ Host string
Port int
AllowedDomains string `xorm:"TEXT"`
ForceSMTPS bool
var auth smtp.Auth
switch source.Auth {
case PlainAuthentication:
- auth = smtp.PlainAuth("", userName, password, source.Addr)
+ auth = smtp.PlainAuth("", userName, password, source.Host)
case LoginAuthentication:
auth = &loginAuthenticator{userName, password}
case CRAMMD5Authentication:
IsActive bool
IsSyncEnabled bool
SMTPAuth string
- SMTPAddr string
+ SMTPHost string
SMTPPort int
AllowedDomains string
SecurityProtocol int `binding:"Range(0,2)"`