Skip to content

Commit 32999e2

Browse files
authored
Don't lookup mail server when using sendmail (#22300) (#22383)
Fix #22287 backport #22300
1 parent 16d7596 commit 32999e2

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

modules/setting/mailer.go

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

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

192203
if MailService.From != "" {
@@ -215,14 +226,6 @@ func newMailService() {
215226
MailService.EnvelopeFrom = parsed.Address
216227
}
217228

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

0 commit comments

Comments
 (0)