Skip to content

Commit 99a675f

Browse files
authored
Don't lookup mail server when using sendmail (#22300)
Fix #22287
1 parent 82235fb commit 99a675f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Diff for: modules/setting/mailer.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,25 @@ func newMailService() {
178178

179179
// we want to warn if users use SMTP on a non-local IP;
180180
// we might as well take the opportunity to check that it has an IP at all
181-
ips := tryResolveAddr(MailService.SMTPAddr)
182-
if MailService.Protocol == "smtp" {
183-
for _, ip := range ips {
184-
if !ip.IsLoopback() {
185-
log.Warn("connecting over insecure SMTP protocol to non-local address is not recommended")
186-
break
181+
// This check is not needed for sendmail
182+
switch MailService.Protocol {
183+
case "sendmail":
184+
var err error
185+
MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
186+
if err != nil {
187+
log.Error("Failed to parse Sendmail args: '%s' with error %v", sec.Key("SENDMAIL_ARGS").String(), err)
188+
}
189+
case "smtp", "smtps", "smtp+starttls", "smtp+unix":
190+
ips := tryResolveAddr(MailService.SMTPAddr)
191+
if MailService.Protocol == "smtp" {
192+
for _, ip := range ips {
193+
if !ip.IsLoopback() {
194+
log.Warn("connecting over insecure SMTP protocol to non-local address is not recommended")
195+
break
196+
}
187197
}
188198
}
199+
case "dummy": // just mention and do nothing
189200
}
190201

191202
if MailService.From != "" {
@@ -214,14 +225,6 @@ func newMailService() {
214225
MailService.EnvelopeFrom = parsed.Address
215226
}
216227

217-
if MailService.Protocol == "sendmail" {
218-
var err error
219-
MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
220-
if err != nil {
221-
log.Error("Failed to parse Sendmail args: %s with error %v", CustomConf, err)
222-
}
223-
}
224-
225228
log.Info("Mail Service Enabled")
226229
}
227230

0 commit comments

Comments
 (0)