@@ -12,6 +12,7 @@ import (
12
12
"code.gitea.io/gitea/modules/log"
13
13
14
14
shellquote "github.com/kballard/go-shellquote"
15
+ ini "gopkg.in/ini.v1"
15
16
)
16
17
17
18
// Mailer represents mail service.
@@ -49,8 +50,8 @@ type Mailer struct {
49
50
// MailService the global mailer
50
51
var MailService * Mailer
51
52
52
- func newMailService ( ) {
53
- sec := Cfg .Section ("mailer" )
53
+ func parseMailerConfig ( rootCfg * ini. File ) {
54
+ sec := rootCfg .Section ("mailer" )
54
55
// Check mailer setting.
55
56
if ! sec .Key ("ENABLED" ).MustBool () {
56
57
return
@@ -70,9 +71,14 @@ func newMailService() {
70
71
if sec .HasKey ("HOST" ) && ! sec .HasKey ("SMTP_ADDR" ) {
71
72
givenHost := sec .Key ("HOST" ).String ()
72
73
addr , port , err := net .SplitHostPort (givenHost )
73
- if err != nil {
74
+ if err != nil && strings .Contains (err .Error (), "missing port in address" ) {
75
+ addr = givenHost
76
+ } else if err != nil {
74
77
log .Fatal ("Invalid mailer.HOST (%s): %v" , givenHost , err )
75
78
}
79
+ if addr == "" {
80
+ addr = "127.0.0.1"
81
+ }
76
82
sec .Key ("SMTP_ADDR" ).MustString (addr )
77
83
sec .Key ("SMTP_PORT" ).MustString (port )
78
84
}
@@ -172,6 +178,9 @@ func newMailService() {
172
178
default :
173
179
log .Error ("unable to infer unspecified mailer.PROTOCOL from mailer.SMTP_PORT = %q, assume using smtps" , MailService .SMTPPort )
174
180
MailService .Protocol = "smtps"
181
+ if MailService .SMTPPort == "" {
182
+ MailService .SMTPPort = "465"
183
+ }
175
184
}
176
185
}
177
186
}
0 commit comments