@@ -13,6 +13,7 @@ import (
1313 "code.gitea.io/gitea/modules/log"
1414
1515 shellquote "github.com/kballard/go-shellquote"
16+ ini "gopkg.in/ini.v1"
1617)
1718
1819// Mailer represents mail service.
@@ -50,8 +51,8 @@ type Mailer struct {
5051// MailService the global mailer
5152var MailService * Mailer
5253
53- func newMailService ( ) {
54- sec := Cfg .Section ("mailer" )
54+ func parseMailerConfig ( rootCfg * ini. File ) {
55+ sec := rootCfg .Section ("mailer" )
5556 // Check mailer setting.
5657 if ! sec .Key ("ENABLED" ).MustBool () {
5758 return
@@ -71,9 +72,14 @@ func newMailService() {
7172 if sec .HasKey ("HOST" ) && ! sec .HasKey ("SMTP_ADDR" ) {
7273 givenHost := sec .Key ("HOST" ).String ()
7374 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 {
7578 log .Fatal ("Invalid mailer.HOST (%s): %v" , givenHost , err )
7679 }
80+ if addr == "" {
81+ addr = "127.0.0.1"
82+ }
7783 sec .Key ("SMTP_ADDR" ).MustString (addr )
7884 sec .Key ("SMTP_PORT" ).MustString (port )
7985 }
@@ -173,6 +179,9 @@ func newMailService() {
173179 default :
174180 log .Error ("unable to infer unspecified mailer.PROTOCOL from mailer.SMTP_PORT = %q, assume using smtps" , MailService .SMTPPort )
175181 MailService .Protocol = "smtps"
182+ if MailService .SMTPPort == "" {
183+ MailService .SMTPPort = "465"
184+ }
176185 }
177186 }
178187 }
0 commit comments