Skip to content

Commit 3a1ed82

Browse files
adelowotechknowlogick
authored andcommitted
Explicitly decide whether to use TLS in mailer's configuration (#5024)
* explicitly decide on using TLS for mail connections * explicitly decide on using TLS for mail connections * keep compatibility
1 parent ce9a517 commit 3a1ed82

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ SKIP_VERIFY =
388388
USE_CERTIFICATE = false
389389
CERT_FILE = custom/mailer/cert.pem
390390
KEY_FILE = custom/mailer/key.pem
391+
; Should SMTP connection use TLS
392+
IS_TLS_ENABLED = false
391393
; Mail from address, RFC 5322. This can be just an email address, or the `"Name" <[email protected]>` format
392394
FROM =
393395
; Mailer user name and password

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
6262
HTTP protocol.
6363
- `USE_COMPAT_SSH_URI`: **false**: Force ssh:// clone url instead of scp-style uri when
6464
default SSH port is used.
65-
65+
6666
### Repository - Pull Request (`repository.pull-request`)
6767
- `WORK_IN_PROGRESS_PREFIXES`: **WIP:,\[WIP\]**: List of prefixes used in Pull Request
6868
title to mark them as Work In Progress
@@ -222,6 +222,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
222222
`FROM` and `SENDMAIL_PATH`.
223223
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
224224
command or full path).
225+
- ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS.
225226

226227
## Cache (`cache`)
227228

@@ -310,8 +311,8 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
310311
- `TOKEN`: **\<empty\>**: You need to specify the token, if you want to include in the authorization the metrics . The same token need to be used in prometheus parameters `bearer_token` or `bearer_token_file`.
311312

312313
## API (`api`)
313-
314-
- `ENABLE_SWAGGER_ENDPOINT`: **true**: Enables /api/swagger, /api/v1/swagger etc. endpoints. True or false; default is true.
314+
315+
- `ENABLE_SWAGGER_ENDPOINT`: **true**: Enables /api/swagger, /api/v1/swagger etc. endpoints. True or false; default is true.
315316
- `MAX_RESPONSE_ITEMS`: **50**: Max number of items in a page.
316317

317318
## i18n (`i18n`)

modules/mailer/mailer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
122122
}
123123
defer conn.Close()
124124

125-
isSecureConn := false
125+
isSecureConn := opts.IsTLSEnabled || (strings.HasSuffix(port, "465"))
126126
// Start TLS directly if the port ends with 465 (SMTPS protocol)
127-
if strings.HasSuffix(port, "465") {
127+
if isSecureConn {
128128
conn = tls.Client(conn, tlsconfig)
129-
isSecureConn = true
130129
}
131130

132131
client, err := smtp.NewClient(conn, host)

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,7 @@ type Mailer struct {
15231523
SkipVerify bool
15241524
UseCertificate bool
15251525
CertFile, KeyFile string
1526+
IsTLSEnabled bool
15261527

15271528
// Sendmail sender
15281529
UseSendmail bool
@@ -1556,6 +1557,7 @@ func newMailService() {
15561557
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
15571558
CertFile: sec.Key("CERT_FILE").String(),
15581559
KeyFile: sec.Key("KEY_FILE").String(),
1560+
IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(),
15591561

15601562
UseSendmail: sec.Key("USE_SENDMAIL").MustBool(),
15611563
SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"),

0 commit comments

Comments
 (0)