]> source.dussan.org Git - gitea.git/commitdiff
Don't lookup mail server when using sendmail (#22300) (#22383)
authorLunny Xiao <xiaolunwen@gmail.com>
Mon, 9 Jan 2023 17:18:03 +0000 (01:18 +0800)
committerGitHub <noreply@github.com>
Mon, 9 Jan 2023 17:18:03 +0000 (12:18 -0500)
Fix #22287
backport #22300

modules/setting/mailer.go

index 5a9b7054b9da54eece7628d4fa9b99e07e41aa3c..e21d8c83cd3061c1162dd8bc259a8a36ec18bb4d 100644 (file)
@@ -179,14 +179,25 @@ func newMailService() {
 
        // we want to warn if users use SMTP on a non-local IP;
        // we might as well take the opportunity to check that it has an IP at all
-       ips := tryResolveAddr(MailService.SMTPAddr)
-       if MailService.Protocol == "smtp" {
-               for _, ip := range ips {
-                       if !ip.IsLoopback() {
-                               log.Warn("connecting over insecure SMTP protocol to non-local address is not recommended")
-                               break
+       // This check is not needed for sendmail
+       switch MailService.Protocol {
+       case "sendmail":
+               var err error
+               MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
+               if err != nil {
+                       log.Error("Failed to parse Sendmail args: '%s' with error %v", sec.Key("SENDMAIL_ARGS").String(), err)
+               }
+       case "smtp", "smtps", "smtp+starttls", "smtp+unix":
+               ips := tryResolveAddr(MailService.SMTPAddr)
+               if MailService.Protocol == "smtp" {
+                       for _, ip := range ips {
+                               if !ip.IsLoopback() {
+                                       log.Warn("connecting over insecure SMTP protocol to non-local address is not recommended")
+                                       break
+                               }
                        }
                }
+       case "dummy": // just mention and do nothing
        }
 
        if MailService.From != "" {
@@ -215,14 +226,6 @@ func newMailService() {
                MailService.EnvelopeFrom = parsed.Address
        }
 
-       if MailService.Protocol == "sendmail" {
-               var err error
-               MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
-               if err != nil {
-                       log.Error("Failed to parse Sendmail args: %s with error %v", CustomConf, err)
-               }
-       }
-
        log.Info("Mail Service Enabled")
 }