-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix use SMTP auth when port 25 is ban problem #16104
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what problem this PR is trying to solve. It is already possible to connect to alternative SMTP ports, also using TLS.
The current code can configure TLS, but now it is based on the support of 25 to jump to use TLS. When 25 is not available, an unlinkable exception will be generated here. If TLS is confirmed in this modification, TLS will be directly used to connect, so as to avoid the abnormal unavailability when port 25 is not available |
@@ -604,6 +604,9 @@ var SMTPAuths = []string{SMTPPlain, SMTPLogin} | |||
|
|||
// SMTPAuth performs an SMTP authentication. | |||
func SMTPAuth(a smtp.Auth, cfg *SMTPConfig) error { | |||
if cfg.TLS { | |||
return SMTPAuthTLS(a,cfg) | |||
} | |||
c, err := smtp.Dial(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c, err := smtp.Dial(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) | |
c, err := smtp.Dial(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) |
Only non TLS connection are used here
// SMTPAuthTLS SMTP authentication by TLS | ||
func SMTPAuthTLS(a smtp.Auth, cfg *SMTPConfig) error { | ||
addr :=fmt.Sprintf("%s:%d", cfg.Host, cfg.Port) | ||
tlsClient, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify:cfg.SkipVerify}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tlsClient, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify:cfg.SkipVerify}) | |
tlsClient, err := tls.Dial("tcp", addr, &tls.Config{InsecureSkipVerify:cfg.SkipVerify}) |
New TLS connection
@@ -648,7 +671,11 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC | |||
|
|||
var auth smtp.Auth | |||
if cfg.Auth == SMTPPlain { | |||
auth = smtp.PlainAuth("", login, password, cfg.Host) | |||
if cfg.TLS { | |||
auth = smtp.PlainAuth("", login, password, fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auth = smtp.PlainAuth("", login, password, fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) | |
auth = smtp.PlainAuth("", login, password, fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)) |
When TLS connection is used, ports need to be added at the same time
Hi @jnan88 I've finally got round to looking at this - apologies for conflicting your PR. I now think I understand the problem. I think we simply have to make a breaking change with the configuration of this source and make it more like the configuration for the mailer. That is:
To that end I'm going to propose a breaking change PR which will attempt to rationalise the configuration. |
…/key options This PR has two parts: Improvements for SMTP authentication: * Default to use SMTPS if port is 465, and allow setting of force SMTPS. * Always use STARTTLS if available * Provide CRAM-MD5 mechanism * Add options for HELO hostname disabling * Add options for providing certificates and keys * Handle application specific password response as a failed user login instead of as a 500. Close go-gitea#16104 Fix creation of new users: * A bug was introduced when allowing users to change usernames which prevents the creation of external users. * The LoginSource refactor also broke this page. Close go-gitea#16104 Signed-off-by: Andrew Thornton <art27@cantab.net>
* Improve SMTP authentication, Fix user creation bugs and add LDAP cert/key options This PR has two parts: Improvements for SMTP authentication: * Default to use SMTPS if port is 465, and allow setting of force SMTPS. * Always use STARTTLS if available * Provide CRAM-MD5 mechanism * Add options for HELO hostname disabling * Add options for providing certificates and keys * Handle application specific password response as a failed user login instead of as a 500. Close #16104 Fix creation of new users: * A bug was introduced when allowing users to change usernames which prevents the creation of external users. * The LoginSource refactor also broke this page. Close #16104 Signed-off-by: Andrew Thornton <art27@cantab.net>
Solve the authentication timeout problem caused by the unavailability of port 25 for SMTP authentication. When using TLS mode, use TLS connection for SMTP communication