Skip to content

Commit

Permalink
Attempt to find sendmail even when not on $PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Nov 12, 2018
1 parent f5ff60a commit bb3d8a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ type Mailer interface {
}

func findMailer() Mailer {
if _, err := exec.LookPath("sendmail"); err == nil {
return &SendMailMailer{}
if path, err := FindSendmail(); err == nil {
return &SendMailMailer{path}
}

return &SMTPMailer{}
Expand Down
16 changes: 14 additions & 2 deletions sendmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ import (
"os/exec"
)

type SendMailMailer struct{}
func FindSendmail() (path string, err error) {
for _, option := range []string{"/usr/sbin/sendmail", "sendmail"} {
path, err = exec.LookPath(option)
if err == nil {
break
}
}
return
}

type SendMailMailer struct {
path string
}

func (m *SendMailMailer) Send(to []string, from string, body []byte) error {
sendmail := exec.Command("sendmail", to...)
sendmail := exec.Command(m.path, to...)
sendmail.Stdin = bytes.NewReader(body)
return sendmail.Run()
}

0 comments on commit bb3d8a7

Please sign in to comment.