make sendmail path configurable using an env var

Closes: #80
This commit is contained in:
chayleaf 2023-10-23 15:31:06 +07:00 committed by Andrew Ayer
parent f38583b79f
commit 74fb03b579
4 changed files with 13 additions and 3 deletions

View File

@ -201,11 +201,16 @@ func main() {
Verbose: flags.verbose, Verbose: flags.verbose,
Script: flags.script, Script: flags.script,
ScriptDir: defaultScriptDir(), ScriptDir: defaultScriptDir(),
SendmailPath: "/usr/sbin/sendmail",
Email: flags.email, Email: flags.email,
Stdout: flags.stdout, Stdout: flags.stdout,
HealthCheckInterval: flags.healthcheck, HealthCheckInterval: flags.healthcheck,
} }
if envVar := os.Getenv("SENDMAIL_PATH"); envVar != "" {
config.SendmailPath = envVar
}
emailFileExists := false emailFileExists := false
if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil { if emailRecipients, err := readEmailFile(defaultEmailFile()); err == nil {
emailFileExists = true emailFileExists = true

View File

@ -218,6 +218,10 @@ and non-zero when a serious error occurs.
: URL of proxy server for making HTTPS requests. `http://`, `https://`, and : URL of proxy server for making HTTPS requests. `http://`, `https://`, and
`socks5://` URLs are supported. By default, no proxy server is used. `socks5://` URLs are supported. By default, no proxy server is used.
`SENDMAIL_PATH`
: Path to the sendmail binary. Defaults to `/usr/sbin/sendmail`.
# SEE ALSO # SEE ALSO
certspotter-script(8) certspotter-script(8)

View File

@ -20,6 +20,7 @@ type Config struct {
WatchList WatchList WatchList WatchList
Verbose bool Verbose bool
SaveCerts bool SaveCerts bool
SendmailPath string
Script string Script string
ScriptDir string ScriptDir string
Email []string Email []string

View File

@ -36,7 +36,7 @@ func notify(ctx context.Context, config *Config, notif notification) error {
} }
if len(config.Email) > 0 { if len(config.Email) > 0 {
if err := sendEmail(ctx, config.Email, notif); err != nil { if err := sendEmail(ctx, config.SendmailPath, config.Email, notif); err != nil {
return err return err
} }
} }
@ -62,7 +62,7 @@ func writeToStdout(notif notification) {
os.Stdout.WriteString(notif.Text() + "\n") os.Stdout.WriteString(notif.Text() + "\n")
} }
func sendEmail(ctx context.Context, to []string, notif notification) error { func sendEmail(ctx context.Context, sendmailPath string, to []string, notif notification) error {
stdin := new(bytes.Buffer) stdin := new(bytes.Buffer)
stderr := new(bytes.Buffer) stderr := new(bytes.Buffer)
@ -77,7 +77,7 @@ func sendEmail(ctx context.Context, to []string, notif notification) error {
args := []string{"-i", "--"} args := []string{"-i", "--"}
args = append(args, to...) args = append(args, to...)
sendmail := exec.CommandContext(ctx, "/usr/sbin/sendmail", args...) sendmail := exec.CommandContext(ctx, sendmailPath, args...)
sendmail.Stdin = stdin sendmail.Stdin = stdin
sendmail.Stderr = stderr sendmail.Stderr = stderr