Skip to content

Commit

Permalink
Don't lookup mail server when using sendmail (#22300) (#22383)
Browse files Browse the repository at this point in the history
Fix #22287
backport #22300
  • Loading branch information
lunny authored Jan 9, 2023
1 parent 16d7596 commit 32999e2
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions modules/setting/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 32999e2

Please sign in to comment.