@@ -12,6 +12,7 @@ import (
1212 "code.gitea.io/gitea/modules/log"
1313
1414 shellquote "github.com/kballard/go-shellquote"
15+ ini "gopkg.in/ini.v1"
1516)
1617
1718// Mailer represents mail service.
@@ -49,8 +50,8 @@ type Mailer struct {
4950// MailService the global mailer
5051var MailService * Mailer
5152
52- func newMailService ( ) {
53- sec := Cfg .Section ("mailer" )
53+ func parseMailerConfig ( rootCfg * ini. File ) {
54+ sec := rootCfg .Section ("mailer" )
5455 // Check mailer setting.
5556 if ! sec .Key ("ENABLED" ).MustBool () {
5657 return
@@ -70,9 +71,14 @@ func newMailService() {
7071 if sec .HasKey ("HOST" ) && ! sec .HasKey ("SMTP_ADDR" ) {
7172 givenHost := sec .Key ("HOST" ).String ()
7273 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 {
7477 log .Fatal ("Invalid mailer.HOST (%s): %v" , givenHost , err )
7578 }
79+ if addr == "" {
80+ addr = "127.0.0.1"
81+ }
7682 sec .Key ("SMTP_ADDR" ).MustString (addr )
7783 sec .Key ("SMTP_PORT" ).MustString (port )
7884 }
@@ -172,6 +178,9 @@ func newMailService() {
172178 default :
173179 log .Error ("unable to infer unspecified mailer.PROTOCOL from mailer.SMTP_PORT = %q, assume using smtps" , MailService .SMTPPort )
174180 MailService .Protocol = "smtps"
181+ if MailService .SMTPPort == "" {
182+ MailService .SMTPPort = "465"
183+ }
175184 }
176185 }
177186 }
0 commit comments