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